During a subprocess call, catch critical windows e

2019-09-19 11:15发布

问题:

"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?

回答1:

Sounds familiar? This will block your subprocess.Popen forever.. until you click the 'OK' button. Add the following code to your module initialization to workaround this issue:

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