Why does python multiprocess manager create thread locks?

>>> import multiprocessing >>> print multiprocessing.Manager().Lock() <thread.lock object at 0x7f64f7736290> >>> type(multiprocessing.Lock()) <class 'multiprocessing.synchronize.Lock'> 

Why is the created object thread.lock and not a multiprocessing.synchronize.Lock , as expected from the multiprocessing object?

+1
source share
2 answers

Managed objects are always proxies; The manager’s goal is to make objects that do not support multiprocessing aware of multiprocessing.

It makes no sense to do this for multiprocessing.Lock() objects; they are implemented using semaphores and fully support multiprocessing without help.

threading.Lock , on the other hand, is not knowledgeable about multiprocessing; there are some differences between threading.Lock() and multiprocessing.Lock() ; the latter supports a timeout when buying a lock, for example.

+1
source

This, of course, is not expected, as the documentation clearly states that Lock()

Create a common threading.Lock object and return the proxy to it.

As for why it returns threading.Lock instead of a multiprocessor object - this is a different story, unfortunately, I can not answer.

0
source

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


All Articles