我正在一个渲染农场工作,需要让我的客户端能够启动多个渲染器实例,而不会阻塞,以便客户端可以接收新命令。我已经成功地实现了这一点,但是我在终止创建的进程方面遇到了困难。
在全局层面上,我定义我的池(以便我可以从任何函数中访问它):
p = Pool(2)
然后我使用apply_async调用我的渲染器:
for i in range(totalInstances):
p.apply_async(render, (allRenderArgs[i],args[2]), callback=renderFinished)
p.close()
该函数会执行完毕,启动后台进程,并等待新的命令。我创建了一个简单的命令,可以终止客户端并停止渲染:
def close():
'''
close this client instance
'''
tn.write ("say "+USER+" is leaving the farm\r\n")
try:
p.terminate()
except Exception,e:
print str(e)
sys.exit()
看起来没有出错(否则会打印错误信息),Python 终止了,但后台进程仍在运行。有人能推荐一种更好的控制这些启动程序的方法吗?
from multiprocessing import util; util.get_logger().setLevel(util.DEBUG)
启用调试日志记录,并粘贴输出。 - schlamarmultiprocessing.log_to_stderr().setLevel(logging.DEBUG)
。render()
是否会启动其他进程,例如使用subprocess
模块? - jfs