Author vstinner
Recipients SAPikachu, gjb1002, sbt, vstinner
Date 2014-06-09.14:36:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1402324568.77.0.241930681746.issue12739@psf.upfronthosting.co.za>
In-reply-to
Content
The PEP 446 partially fixes this issue. The issue #19764 should fix it completly. Since you are using Python 2, you should not wait until the issue is fixed, but work around it.

To workaround the issue: use you own lock around the creation of processes. Example:
---
lock = threading.Lock()
...

def run_command(...):
   with lock:
      proc = subprocess.Popen(...)
   return proc.communicate()
---

The problem is that a thread B may inherit the handle of a pipe from handle A because the pip is marked as inheritable, and the subprocess module must use CreateProcess() with bInheritHandles parameter set to True to be able to redirect stdout.

Said differently: the subprocess is not thread-safe, you have to use your own lock to workaround race conditions.
History
Date User Action Args
2014-06-09 14:36:08vstinnersetrecipients: + vstinner, gjb1002, sbt, SAPikachu
2014-06-09 14:36:08vstinnersetmessageid: <1402324568.77.0.241930681746.issue12739@psf.upfronthosting.co.za>
2014-06-09 14:36:08vstinnerlinkissue12739 messages
2014-06-09 14:36:08vstinnercreate