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://www.ptt.cc/bbs/Python/M.1403579125.A.615.html
不太確定原來用 multiprocessing 配 fabric 的目的,有找到一個參考: