私はa Python issue - closed/fixedに基づいて、この小さなテストクラスを書いて、それはただ、この場合はファイルを、/ tmpに/ジャンクを作成subprocess.Popenはスレッドセーフではありませんか?
from subprocess import Popen, PIPE
from threading import Thread
OUTPUT = "asl;dkfhqwiouethnjzxvnhsldfhuyasdhofuiweqamchuisemfawepfhuaipwemhfuaehfclkuehnflw ehfcoiuwehfiuwmhefuiwehfoiuhSfcl hfulh fuiqhuif huiwafh uiahf iUH fhh flkJH fl HASLFuhSAIULFhSUA HFulSAHfOI SUFChiuwqhncriouweycriuowanbyoUIWCryu iWyruawyrouiWYRcoiu YCRoiuNr uyr oUIAWryocIUWRNyc owuroiuNr cuWyrnawueitcnoy U IuiR yiuowaYnorc oWIUAr coiury iuoAW rnuoi asdfsdfd\n"
class X(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
print("Running")
for i in xrange(10):
s = Popen(
"cat /tmp/junk",
shell=True,
stdout=PIPE,
universal_newlines=True
)
output = s.communicate()[0]
if not output == OUTPUT:
print("Error: %r" % output)
XThreads = set([])
for i in xrange(1000):
XThreads.add(X())
for x in XThreads:
x.start()
のFedora 15
でPython 2.7.1で発生しているようで、持っていますOUTPUT
の内容で、最後の改行を除いています。
これを実行すると、すべての行で「実行中」が表示されることが期待されます。ただし、「Running」または「RunningRunning \ n \ nRunning」と表示されることがあります。
(実際の問題の引用を削除しました。これは、@ phihagの回答のおかげで間違った症状でした)。
実際問題:https://stackoverflow.com/questions/9338409/python-subprocess-popen-corrupts-binary-streams
ありがとう、私は私の問題を発見したと思うが、実際の例を提供するために複数のファイルをアップロードする必要があります - ここでそれを行う方法がわからない...手伝ってもらえますか? – CrackerJack9
もっと興味深いことに、本当の問題 - http://stackoverflow.com/questions/9338409/python-subprocess-popen-corrupts-binary-streams – CrackerJack9
@ CrackerJack9いくつかの変更を加えれば、マルチファイルのPythonプログラムを一つにする。それができない場合(またはプログラムが本当に長い場合)、ファイルを[gist](https://gist.github.com/)または[pastebin](http://pastebin.com)にアップロードしてください。 – phihag