[issue6721] Locks in python standard library should be sanitized on fork

Richard Oudkerk report at bugs.python.org
Sat Jun 2 20:06:21 CEST 2012


Richard Oudkerk <shibturn at gmail.com> added the comment:

Lesha, the problems about "magical" __del__ methods you are worried about actually have nothing to do with threading and locks.  Even in a single threaded program using fork, exactly the same issues of potential corruption would be present because the object might be finalized at the same in multiple processes.

The idea that protecting the object with a thread lock will help you is seriously misguided UNLESS you also make sure you acquire them all before the fork -- and then you need to worry about the order in which you acquire all these locks.  There are much easier and more direct ways to deal with the issue than wrapping all objects with locks and trying to acquire them all before forking.

You could of course use multiprocessing.Lock() if you want a lock shared between processes.  But even then, depending on what the __del__ method does, it is likely that you will not want the object to be finalized in both processes.

However, the suggestion that locked-before-fork-locks should by default raise an error is reasonable enough.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6721>
_______________________________________


More information about the Python-bugs-list mailing list