[問題] multiprocess 與 fabric 混用出錯

看板Python作者 (善液)時間9年前 (2014/06/14 00:03), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
原始目的為模擬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? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 202.156.34.136 ※ 文章網址: http://www.ptt.cc/bbs/Python/M.1402675422.A.B5E.html
文章代碼(AID): #1Jco3UjU (Python)
文章代碼(AID): #1Jco3UjU (Python)