classification
Title: import on Windows: please call SetErrorMode first
Type: Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: christian.heimes, georg.brandl, papadopo, srid
Priority: high Keywords:

Created on 2004-11-19 14:02 by papadopo, last changed 2009-06-10 17:57 by srid. This issue is now closed.

Messages (5)
msg60600 - (view) Author: Dimitri Papadopoulos (papadopo) Date: 2004-11-19 14:02
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.
msg60601 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-26 06:21
Logged In: YES 
user_id=1188172

That seems to be a correct wish. Is there any problem with
SetErrorMode?
msg61344 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-20 19:27
I'll take fix it for 2.6
msg61591 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-23 17:15
Applied in 60221
msg89220 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-06-10 17:57
i.e., fixed in r60221
History
Date User Action Args
2009-06-10 17:57:30sridsetnosy: + srid
messages: + msg89220
2008-01-23 17:15:27christian.heimessetstatus: open -> closed
resolution: fixed
messages: + msg61591
2008-01-20 19:27:53christian.heimessetversions: + Python 2.6, - Python 2.3
nosy: + christian.heimes
messages: + msg61344
priority: normal -> high
assignee: christian.heimes
components: + Interpreter Core, - Library (Lib)
2004-11-19 14:02:14papadopocreate