Issue 1069410: import on Windows: please call SetErrorMode first (original) (raw)
Hi,
We have a problem with "import" on Windows XP.
If we attempt to import a missing Python module, an exception is raised. That's OK.
If we attempt to import an existing Python module depending on a missing DLL, then the Windows runtime will pop up an error message, before the exception is raised by Python. That's not OK. I would expect an exception should be thrown, but I believe the Windows error message should not be displayed.
I guess the error message originates in the win32 LoadLibrary function: http://msdn.microsoft.com/library/en-us/dllproc/base/loadlibrary.asp According to this documentation: To enable or disable error messages displayed by the loader during DLL loads, use the SetErrorMode function. SetErrorMode is documented here: http://msdn.microsoft.com/library/en-us/debug/base/seterrormode.asp
I believe Python should handle the DLL error instead of letting the system handle it. The default behavior is not appropriate for most Python programs. The Python way of dealing with errors is raising an exception, not passing errors to the system and let it pop up platform specific error messages.
We're running Python 2.3.4 on Windows XP.
Background: The problems occurs when importing the PyMat library. This Matlab wrapper depends on a Matlab DLL. We don't know before hand whether Matlab is present or not on the system. We expect import pymat to raise an exception if Matlab is not installed. We don't want the user to have to click in the annoying control popped up by the Windows runtime.