Python multiprocessor class manager thread object / security process

I have the following class, which is distributed among several consumers (using the producer / consumer methodology). My question includes methods called this class. Do I need to implement locks or a secure stream of manager classes?

import multiprocessing as mp
from multiprocessing.manager import BaseManager

class SampleClass(object):

    def __init__(self):
        self._count = 0

    # Does locking need to be implemented here?
    def increment(self):
        self._count += 1

BaseManager.register('SampleClass', SampleClass)
manager = BaseManager()
manager.start()

instance = manager.SampleClass()

jobs = []
for i in range(0, 5):
    p = mp.Process(target=some_func, args=(instance,))
    jobs.append(p)
    p.start()

for p in jobs:
    p.join()
+7
source share
1 answer

I think so. As stated in the commentary to this other question:

  1. multiprocessing: how to split between multiple processes?

Is manager.dict()this process safe?

@LorenzoBelli, , , , - . multiprocessing.Manager() SyncManager, !

0

Source: https://habr.com/ru/post/1682280/


All Articles