HELP: Python.exe Application Error using Extensions on Win2000

Desaulniers, Peter Peter.Desaulniers at
Wed Mar 8 22:59:03 CET 2000

Hello Fellow Pythoners,

I hope this is the appropriate list for this type of request.

The architecture is a python method that make a call into a C extension
which in turn loads a 3rd party DLL (via LoadLibrary and later
FreeLibrary).  A Py_Object is created in the extension which includes a
member object obtained from a call into the DLL. The Py_Object is returned
to the python method.  The python method then makes calls to the methods on
the 3rd party object via the Py_Object.  The code works fine. Everything
happens as is should then the error occurs at the very end when its cleaning

I am getting a Python.exe Application error indicating that I am trying to
"write" to an unacceptable memory location on a Win2000 system.  The exact
same code works fine on WinNT 4.0.   I have determined that it is occurring
during the Python cleanup as the Python process is shutting down. This is
confirmed by doing an os._exit(0) as the last line in the top level module
being executed (to prevent the clean up, the problem still occurs with a
sys.exit(0) in the same location).  So, something changed in Win2000 that is
instigating this problem.

If I skip the use of the extension altogether and let the rest of the python
method to work without the feature obtained from the 3rd party DLL then I
get no problem indicating that it is the use of the C extension that is
causing the error.

The extension has a dealloc method  for the Py_Object which gets called by
python.  The dealloc method frees allocated memory and DECREFs objects. The
dealloc is called and does complete before the error occurs.  The problem
occurs whether dealloc is allowed to do its stuff or not (e.g. returning at
the beginning of the dealloc method).  

Has anyone seen a similiar problem with the use of C extensions and / or 3rd
party DLLs on Win2000? And if so, how did you resolve the problem?

Or, in a more general sense, has anyone discovered some less than obvious
things (e.g. freeing of memory, DECREFs, etc) that need to be done for
cleaning up C extensions, particularly those that in turn use a 3rd party
DLL.  I am hunting for any clues here.

Has anyone discovered any errors arising with python applications that works
on NT 4.0 but failed on Win2000?

Any suggestions are greatly appreciated.


-- Peter Desaulniers

More information about the Python-list mailing list