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 Pankrat
Recipients Pankrat
Date 2008-03-17.13:31:50
SpamBayes Score 0.04725159
Marked as misclassified No
Message-id <1205760712.39.0.906940637593.issue2320@psf.upfronthosting.co.za>
In-reply-to
Content
Pythons subprocess module has a race condition when stdin is used. The
problem can be reproduced with the following script (based on the script
in issue "#1731717"/"msg32210" (slightly changed to use stdin):

----
import sys, os, threading, subprocess, time

class X(threading.Thread):
  def __init__(self, *args, **kwargs):
    super(X, self).__init__(*args, **kwargs)
    self.start()

def tt():
  s = subprocess.Popen(("cat"), stdin=subprocess.PIPE)
  s.communicate(input = '#')

for i in xrange(20):
  X(target = tt)
----

On multi-processor (or multi-core) machines the script hangs fairly
reliably.

Protecting the Popen call with a lock solves the problem. I searched the
documentation if using stdin with subprocess.Popen was not thread-safe,
but found no indication.

Tested with Python 2.5.1, 2.5.2 and 2.6a1. The problem can be reproduced
with all mentioned versions.
History
Date User Action Args
2008-03-17 13:31:52Pankratsetspambayes_score: 0.0472516 -> 0.04725159
recipients: + Pankrat
2008-03-17 13:31:52Pankratsetspambayes_score: 0.0472516 -> 0.0472516
messageid: <1205760712.39.0.906940637593.issue2320@psf.upfronthosting.co.za>
2008-03-17 13:31:51Pankratlinkissue2320 messages
2008-03-17 13:31:51Pankratcreate