This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Gary.Yee
Recipients Gary.Yee
Date 2011-04-20.17:17:35
SpamBayes Score 5.495604e-15
Marked as misclassified No
Message-id <1303319858.78.0.604473058282.issue11891@psf.upfronthosting.co.za>
In-reply-to
Content
Background: 

I'm using multiprocessing not to run jobs in parallel, but to run functions in a different process space so they can be done as a different user.  I am thus using multiprocessing in a multithreaded (Linux) application.

Problem:

In multiprocessing/forking.py the poll() function is not thread safe.  If multiple threads call poll() you could have two back-to-back calls to os.waitpid() on the same PID (this happens frequently when multiprocessing's _cleanup() function is called).

Traceback (most recent call last):
  File "/opt/scyld/foo.py", line 178, in call
    pool = Pool(processes=1)
  File "/opt/scyld/python/2.6.5/lib/python2.6/multiprocessing/__init__.py", line 227, in Pool
    return Pool(processes, initializer, initargs)
  File "/opt/scyld/python/2.6.5/lib/python2.6/multiprocessing/pool.py", line 104, in __init__
    w.start()
  File "/opt/scyld/python/2.6.5/lib/python2.6/multiprocessing/process.py", line 99, in start
    _cleanup()
  File "/opt/scyld/python/2.6.5/lib/python2.6/multiprocessing/process.py", line 53, in _cleanup
    if p._popen.poll() is not None:
  File "/opt/scyld/python/2.6.5/lib/python2.6/multiprocessing/forking.py", line 106, in poll
    pid, sts = os.waitpid(self.pid, flag)
OSError: [Errno 10] No child processes


Suggested Fix:

Wrap the os.waitpid() call in a try/except block looking for OSError 10 exceptions and return the returncode currently available in that event.  The one potential problem this introduces is if someone calls os.waitpid() on that PID on the process without going through forking.py.  This will result in self.returncode never being set to a non-None value.  If you're using the multiprocessing module to create processes, however, you should be also using it to clean up after itself.

I've attached a test file.
History
Date User Action Args
2011-04-20 17:17:39Gary.Yeesetrecipients: + Gary.Yee
2011-04-20 17:17:38Gary.Yeesetmessageid: <1303319858.78.0.604473058282.issue11891@psf.upfronthosting.co.za>
2011-04-20 17:17:35Gary.Yeelinkissue11891 messages
2011-04-20 17:17:35Gary.Yeecreate