[issue9573] importing a module that executes fork() raises RuntimeError

Alex Roitman report at bugs.python.org
Tue Aug 17 23:07:07 CEST 2010


Alex Roitman <rshura at gmail.com> added the comment:

gregory.p.smith: This is my use case: we had the following situation with the test scripts at work.  Each script is required to import TestApi module in order to run the tests.  That module in turn imported the module that forks, and in the parent waits for the child to exit, then kills all child's children processes.  That way tests don't leave any processes behind.

So any script that imported the cleanup module, whether directly or via another module, had this cleanup functionality "for free". One workaround for this issue would be to change all existing test scripts to call the cleanup function, instead of the cleanup module calling it at the module level.

I can see your reservations about forking/starting threads during import, but it seems like it either should work or it should be disallowed.  The thing is, the actual import is working fine with the fork() call, it's releasing the lock that is messed up, because it was not initialized correctly after the fork.  The patch attached by ncoghlan looks good though.

----------

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


More information about the Python-bugs-list mailing list