我需要使用线程和SSH在精确的时刻分别启动多个远程作业。所以我写道:
def dojob(hostname):
command = "echo Done"
p = Popen(['ssh','%s@%s' % (user, hostname), command], stdout=PIPE, shell=False)
output = p.communicate()[0].strip()
print output
[...]
fire_starter = [Timer(t, dojob, [y]) for t,y in zip(instant, hosts)]
for e in fire_starter:
e.start()
代码可以工作,但是我的操作系统充斥着Zombies。老实说,我相信通信()方法负责子进程,等待它终止。我哪里错了?