作者keitheis (无)
标题Re: [问题] multiprocess 与 fabric 混用出错
时间Tue Jun 24 11:05:19 2014
不太确定原来用 multiprocessing 配 fabric 的目的,有找到一个参考:
http://stackoverflow.com/questions/6446578/multiprocess-module-with-paramiko
可以把 fabric 与 paramiko 升到最新版试试?
另外 fabric 本身有支援 parallel 也可以参考看看
http://fabric.readthedocs.org/en/1.3.4/usage/parallel.html
※ 引述《SonEat (善液)》之铭言:
: 原始目的为模拟torque
: 希望可以让一个含多个任务的list来对1个ndoe的cores进行排队执行
: 程式码:
: -----------------main.py--------------------------------
: from multiprocessing import Pool
: from fabric.api import run,env,cd,local
: from fabric.tasks import execute
: def run_script(x):
: run(x)
: def nodeq(scriptlist):
: pool = Pool(processes=2)
: pool.map(run_script,scriptlist)
: scriptlist=['./sleep.sh', './sleep.sh','./sleep.sh']
: if __name__ == '__main__':
: execute(nodeq,scriptlist,hosts='node1')
: ------------------sleep.sh------------------------------
: #! bash
: sleep 10
: -------------------------------------------------------
: 如果执行过程没有任何错误则这段程式没问题
: 但如果过程出错
: 例如scriptlist当中的某一元素给一个不存在的路径
: 则程式执行完正常的script後会卡住无法自动退出
: 检查发现是因为pool仍然在等待子程序run的回应
: 而fabric的run对於error是这样写的
: (/fabric/operations.py 932行)
: if status not in env.ok_ret_codes:
: out.failed = True
: msg = "%s() received nonzero return code %s while executing" % (
: which, status
: )
: if env.warn_only:
: msg += " '%s'!" % given_command
: else:
: msg += "!\n\nRequested: %s\nExecuted: %s" % (
: given_command, wrapped_command
: )
: ---------> error(message=msg, stdout=out, stderr=err)
: 也就是fabric的run遇到错误就让程序自杀
: 而父程序的pool只能傻傻等待回应
: 如果去掉 error那行就能正常退出程式
: 问题:
: 在不改写fabric原始模组的前提下,请问是否有方法可以修正这个bug?
--
keitheis ")
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.45.252.254
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Python/M.1403579125.A.615.html