本文整理汇总了Python中ThreadPool.ThreadPool.addFinishCb方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.addFinishCb方法的具体用法?Python ThreadPool.addFinishCb怎么用?Python ThreadPool.addFinishCb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadPool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.addFinishCb方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OnExecute
# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import addFinishCb [as 别名]
def OnExecute(self, button_desc):
if "run_detect_button" == button_desc:
desc_fail = "运行检查程序返回失败\r\n"
desc_success = "所有设备运行检查程序返回成功\r\n"
cmds_txt = "./cmds/cmds_detect.txt"
if "scan_result_button" == button_desc:
desc_fail = "查看检查结果返回失败\r\n"
desc_processexit = "设备检测程序异常退出\r\n"
desc_success = "所有设备查看检查结果返回成功\r\n"
cmds_txt = "./cmds/cmds_scan.txt"
ips = self.ParseIp(self.ip.GetValue().encode('utf-8').split(';'))
if False == ips:
return
cmds = getContent(cmds_txt,"lines")
if False == cmds:
return
pool = ThreadPool( _THREAD_POOL_SIZE )
for ip in ips:
pool.addTask( telnetTask, ip = ip, cmds = cmds)
#必须放在pool.addFinishCb( finish_event,pool=pool)之前
def finish_event( *args, **kwargs ):
pool = kwargs['pool']
result = pool.show()
# [[ip,[ret1,ret2]],...]
result_to_show = ""
for ip_retlist in result:
ip = ip_retlist[0]
retlist = ip_retlist[1]
if ["fail"] == retlist:
result_to_show += ip + " Telnet时抛出了异常\r\n"
else:
t = retlist[len(retlist)-1].split("\r\n")
status = t[len(t)-2]
if "0" == status:
pass
elif "1" == status:
result_to_show += ip + desc_fail#desc_fail能访问到
elif "2" == status:
result_to_show += ip + desc_processexit
else:
result_to_show += ip + " 脚本返回意料之外的值\r\n"
last_cmd_result = retlist[len(retlist)-1]
logging.warning(toUnicode(last_cmd_result))
if "" == result_to_show:
result_to_show = desc_success
logging.warning(result_to_show.decode('utf-8'))
result_to_show = self.result_text.GetValue()+getCurTime().decode("ascii")+" ".decode("utf-8")+result_to_show.decode("utf-8")
self.result_text.SetValue(result_to_show)
self.ButtonStatus("Enable")
pool.addFinishCb( finish_event,pool=pool)
pool.start()
self.ButtonStatus("Disable")
示例2: OnPatch
# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import addFinishCb [as 别名]
def OnPatch(self,evt):
desc_ddr2 = "DDR2不需要修补补丁\r\n"
desc_fail = " 修补补丁失败\r\n"
desc_md5 = "补丁Md5值校验失败\r\n"
desc_notexist = "补丁文件不存在\r\n"
desc_success = "所有设备打补丁成功,请断电\r\n"
cmds_txt = "./cmds/cmds_patch.txt"
ips = self.ParseIp(self.ip.GetValue().encode('utf-8').split(';'))
if False == ips:
return
cmds = getContent(cmds_txt,"lines")
if False == cmds:
return
pool = ThreadPool( _THREAD_POOL_SIZE )
for ip in ips:
pool.addTask( telnetTask, ip = ip, cmds = cmds)
#必须放在pool.addFinishCb( finish_event,pool=pool)之前
def finish_event( *args, **kwargs ):
pool = kwargs['pool']
result = pool.show()
# [[ip,[ret1,ret2]],...]
result_to_show = ""
for ip_retlist in result:
ip = ip_retlist[0]
retlist = ip_retlist[1]
if ["fail"] == retlist:
result_to_show += ip + " Telnet时抛出了异常\r\n"
else:
t = retlist[len(retlist)-1].split("\r\n")
status = t[len(t)-2]
if "0" == status:
pass
elif "1" == status:
result_to_show += ip + desc_ddr2
elif "2" == status:
result_to_show += ip + desc_md5
elif "3" == status:
result_to_show += ip + desc_notexist
elif "4" == status:
result_to_show += ip + desc_fail
else:
result_to_show += ip + " 脚本返回意料之外的值\r\n"
last_cmd_result = retlist[len(retlist)-1]
logging.warning(toUnicode(last_cmd_result))
if "" == result_to_show:
result_to_show = desc_success
if "请断电" in desc_success:
wx.CallAfter(pub.sendMessage,"importNote",("请将设备断电"))
logging.warning(result_to_show.decode('utf-8'))
result_to_show = self.result_text.GetValue()+getCurTime().decode("ascii")+" ".decode("utf-8")+result_to_show.decode("utf-8")
self.result_text.SetValue(result_to_show)
self.ButtonStatus("Enable")
pool.addFinishCb( finish_event,pool=pool)
pool.start()
self.ButtonStatus("Disable")