windows – 如何在子进程中启动崩溃(很少)应用程序
我正在使用
python应用程序,它需要每天执行大约2 000次专有应用程序(它会不时崩溃).
问题是当应用程序崩溃时,Windows自动触发WerFault会使程序挂起,因此python’s 如果关于使用睡眠;轮询;杀;终止但这意味着失去使用communication()的能力,应用程序可以从几毫秒运行到2小时,因此设置固定超时将无效 我也试过turning on automatic debugging(使用一个脚本,它会占用应用程序的崩溃转储并终止id),但不知怎的,这个howto在我的服务器上不起作用(WerFault仍然出现并等待用户输入). 其他几个教程如this也没有任何效果. 题: 替代问题:在python中有一种优雅的方式如何检测应用程序崩溃(是否显示了WerFault) 解决方法
简单(和丑陋)的答案,不时监视WerFault.exe实例,特别是与违规应用程序的PID相关联的实例.杀了它.处理WerFault.exe很复杂,但您不想禁用它 – 请参阅
Windows Error Reporting服务.
>按名称获取与WerFault.exe匹配的进程列表.我用 这是一个简单的实现. def kill_proc_kidnapper(self,child_pid,kidnapper_name='WerFault.exe'): """ Look among all instances of 'WerFault.exe' process for an specific one that took control of another faulting process. When 'WerFault.exe' is launched it is specified the PID using -p argument: 'C:WindowsSysWOW64WerFault.exe -u -p 5012 -s 68' | | +-> kidnapper +-> child_pid Function uses `argparse` to properly decode process command line and get PID. If PID matches `child_pid` then we have found the correct parent process and can kill it. """ parser = argparse.ArgumentParser() parser.add_argument('-u',action='store_false',help='User name') parser.add_argument('-p',type=int,help='Process ID') parser.add_argument('-s',help='??') kidnapper_p = None child_p = None for proc in psutil.get_pid_list(): if kidnapper_name in proc.name: args,unknown_args = parser.parse_known_args(proc.cmdline) print proc.name,proc.cmdline if args.p == child_pid: # We found the kidnapper,aim. print 'kidnapper found: {0}'.format(proc.pid) kidnapper_p = proc if psutil.pid_exists(child_pid): child_p = psutil.Process(child_pid) if kidnapper_p and child_pid: print 'Killing "{0}" ({1}) that kidnapped "{2}" ({3})'.format( kidnapper_p.name,kidnapper_p.pid,child_p.name,child_p.pid) self.taskkill(kidnapper_p.pid) return 1 else: if not kidnapper_p: print 'Kidnapper process "{0}" not found'.format(kidnapper_name) if not child_p: print 'Child process "({0})" not found'.format(child_pid) return 0 现在,taskkill函数使用正确的PID调用taskkill命令. def taskkill(self,pid): """ Kill task and entire process tree for this process """ print('Task kill for PID {0}'.format(pid)) cmd = 'taskkill /f /t /pid {0}'.format(pid) subprocess.call(cmd.split()) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- windows安装mysql8
- 如何在Windows XP上以只读方式安装硬盘?
- powershell – 我的服务帐户需要什么来解决robocopy中的“管
- wpf – 如何将Themes / Generic.xaml连接到window1.xaml?
- Windows锁屏幕后面会发生什么?
- Windows PowerShell中特定文件类型的递归列表
- 不同版本的iperf for windows会产生完全不同的结果
- hosted-exchange – 使用Microsoft Online Services托管Exc
- 自动获取windows或者linux系统IP
- .net – 在Windows上生成ActivityTracing事件日志