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

Gregory P. Smith report at bugs.python.org
Fri Jun 1 03:26:56 CEST 2012


Gregory P. Smith <greg at krypto.org> added the comment:

threading locks cannot be used to protect things outside of a single process.  Any code using them to do that is broken.

In your examples you are suggesting a class that wants to do one or more mysql actions within a destructor and worried that the __del__ method would be called in the fork()'ed child process.

With the subprocess module, this will never happen.  the child exec's or does a hard exit.   http://hg.python.org/cpython/file/bd2c2def77a7/Modules/_posixsubprocess.c#l634

When someone is using os.fork() directly, they are responsible for all destructors in their application behaving sanely within the child process.

Destructors are an evil place to put code that does actual work and are best avoided.  When required, they must be written defensively because they really cannot depend on much of the Python execution environment around them being in a functional state as they have no control over _when_ they will be called during shutdown.  Nothing new here.

----------

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


More information about the Python-bugs-list mailing list