简体   繁体   English

在子流程调用期间,使用Python捕获严重的Windows错误,而不是通过显示讨厌的错误弹出窗口来让操作系统处理它

[英]During a subprocess call, catch critical windows errors in Python instead of letting the OS handle it by showing nasty error pop-ups

"The application failed to initialize properly ... Click on OK,to terminate the application." “应用程序无法正确初始化。单击确定,以终止应用程序。” is the message from the error pop-up. 是错误弹出窗口中的消息。 What is the way to catch these errors in Python code? 用Python代码捕获这些错误的方法是什么?

Sounds familiar? 听起来很熟悉? This will block your subprocess.Popen forever.. until you click the 'OK' button. 这将阻止您的subprocess.Popen进程。请永久打开。直到您单击“确定”按钮。 Add the following code to your module initialization to workaround this issue: 将以下代码添加到模块初始化中以解决此问题:

import win32api, win32con
win32api.SetErrorMode(win32con.SEM_FAILCRITICALERRORS |
                      win32con.SEM_NOOPENFILEERRORBOX)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM