(multiprocessing.Process) (multiprocessing.Queue), , .
:
import multiprocessing
def processWorker(input, result):
work = input.get()
pipe = subprocess.Popen(command, stdout = subprocess.PIPE,
stderr = subprocess.PIPE, shell = True)
stdout, stderr = pipe.communicate()
result.put(pipe.returncode)
input = multiprocessing.Queue()
result = multiprocessing.Queue()
p = multiprocessing.Process(target = processWorker, args = (input, result))
p.start()
commandlist = ['ls -l /', 'ls -l /tmp/']
for command in commandlist:
input.put(command)
for i in xrange(len(commandlist)):
res = result.get(block = True)
if not res is 0:
print 'One command failed'
, , , workid (workid , ).
.Queue , stdout/err, .
, .
- , , get max, :
import Queue
try:
res = result.get(block = True, timeout = 10)
except Queue.Empty:
print error