On 10 January 2013 18:48, Tom Bowles <tomthemig...@googlemail.com> wrote:
>
> On 10 January 2013 17:15, Aahz <a...@pythoncraft.com> wrote:
>>
>> On Thu, Jan 10, 2013, Tom Bowles wrote:
>> >
>> > Hi,  I have a question regarding python finalisation when using pywin32.
>> > The details are at
>> > http://stackoverflow.com/questions/14257654/how-should-i-or-should-i-finalize-python-in-the-presence-of-pywin32.
>> > I can reproduce the question here if preferred, but there's a lot of
>> > formatting and I'm posting this from a phone. Hope the stackoverflow link
>> > is acceptable.
>>
>> I'm certainly not looking at Stackoverflow, and it disrupts the archives
>> of this list.  Please repeat your full question here.
>> --
>> Aahz (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/
>>
>> Weinberg's Second Law: If builders built buildings the way programmers wrote
>> programs, then the first woodpecker that came along would destroy 
>> civilization.
>
>
>
> Sure. For a more specialist audience than SO it boils down to:
>
> 1. Should I call PyWinGlobals_Free() before calling Py_Finalize()? If I don't 
> I get errors,  which I can give more detail about if you want.
>
>
> 2. Why does pycom's dllmain.cpp contain a comment implying that it is not 
> safe to "ever" finalize python "in the COM world".
> 3. What happened to the pycom-dev archive? pythonpros.com, which all the 
> links to it I can find point to, appears to be a sedo parking thing.
>
>
> Tom


Does anybody have any thoughts on this?

If I call Py_Finalize() without calling PyWinGlobals_Free(), then
after I re-initialize python and start using pywin32 again I get
"NoneType is not callable" errors, which appear to originate on line 3
of the string that is executed with PyRun_String() in
pywintypesmodule.cpp. This string contains the definition of a class
called "error".

It appears that the class definition is somehow surviving across the
python reinitialisation, but in a broken state, so that when it
eventually gets used again the value of "len" is None, instead of the
len() function as it should be.

Calling PyWinGlobals_Free() before finalising python causes the state
to be reset so that on reinitialisation the "error" class definition
string gets executed again with PyRun_String(). This avoids the errors
I have experienced, but I don't know if it's the right thing to do.

On the one hand, at the C++ code level it looks plausible that the
PyWinGlobals_Free() export is intended to be called as a cleanup
before finalisation. Also, in the dllmain.cpp file for pycom, there is
commented out finalisation code which calls PyWinGlobals_Free(), which
suggests it might be the right thing to do.

On the other hand, there is no mention at all of PyWinGlobals_Free()
in the pywin32 documentation, and there is no indication there (or
anywhere else I can find) that it is necessary to do anything special
before finalising python when using pywin32. Also, the dllmain.cpp
file in pycom has a comment suggesting that finalisation might not be
safe at all, and the file mentions the "pycom-dev" archives as a
source of further information. However, these archives no longer
appear to exist. It looks like the domain registration for
pythonpros.com has expired.

Any clarification you can provide would be very helpful.

Thanks,
Tom
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to