test1.py:Subprocess.poll() trả về giá trị sai
process = Popen(["python","test2.py"])
time.sleep(3)
alive = process.poll()
if alive is None:
print "Still running"
else:
print "Not running\r\n"
print "%r" % alive
test1.py Output:
Not running
2
test2.py:
time.sleep(30)
print "done"
Điều gì đang xảy ra? Không nên trả lại "Vẫn chạy"?
Bởi vì kết quả mâu thuẫn ở đây là mã test1.py đầy đủ:
import cStringIO
import os
import cgi
import time
from subprocess import Popen
def application(environ, start_response):
headers = []
headers.append(('Content-Type', 'text/plain'))
write = start_response('200 OK', headers)
input = environ['wsgi.input']
output = cStringIO.StringIO()
process = Popen(["python","test2.py"])
time.sleep(3)
alive = process.poll()
if alive is None:
print >> output, "Still running"
else:
print >> output, "Not running\r\n"
print >> output, "%r" % alive
output.write(input.read(int(environ.get('CONTENT_LENGTH', '0'))))
return [output.getvalue()]
Cập nhật test1.py:
process = Popen(["python","C:/wamp/www/python/popen/test2.py"], shell=True)
time.sleep(5)
alive = process.poll()
if alive is None:
#print >> output, "%r" % alive
print >> output, "Still running"
else:
print >> output, "Not running"
print >> output, "%r" % alive
print >> output, "Current working dir : %s" % os.getcwd()
print >> output, os.strerror(0)
Output Cập nhật:
Not running
0
Current working dir : C:\wamp\bin\apache\apache2.2.22
No error
Làm việc tốt cho tôi. Đầu ra của tôi là 'Vẫn đang chạy'. – RanRag
da fuq ... sau đó tôi có một vấn đề mới. Bất kỳ ý tưởng? Tôi sẽ đăng thêm mã ... BTW Tôi nghĩ rằng nó là lạ, bởi vì không có nơi trong tìm kiếm của tôi đã làm tôi tìm thấy một "2" như là một kết quả cho cuộc thăm dò(). – Rawr
Kết quả tương tự với RanRag, tôi cũng nhận được "Vẫn đang chạy". –