On Thu, Jul 1, 2010 at 9:03 PM, Craig McQueen
<[email protected]> wrote:
> On Wed 16/06/2010 12:03 PM, Craig McQueen wrote:
>
> Craig McQueen wrote:
>
> Craig McQueen wrote:
>
> Hello,
>
> I've got a Python program that does client COM programming on Windows, for
> Excel and National Instruments TestStand.
>
> When I convert it to a Windows EXE file with cx_Freeze, at exit, I get a
> message like this:
>
>     Exception KeyError: KeyError(2768,) in <module 'threading' from
> '<frozen>'> ignored
>
> It seems not to be an exception; rather some sort of debug message that I
> can't get rid of--a little unusual.
>
> Any ideas why this might be happening? I assume it is something to do with a
> COM-related thread not finishing "correctly" at exit. The number quoted in
> the KeyError appears likely to be a Windows process/thread ID. This message
> doesn't occur when running the original Python program; only when running
> the cx_Freeze-generated EXE.
>
> This is using cx_Freeze 4.1.2 with Python 2.6.5 on Windows 2000.
>
> Regards,
> Craig McQueen
>
>
> This may be related:
> http://bugs.python.org/issue1596321
>
> But I'm not sure what might be a good work-around when using cx_Freeze.
>
> Regards,
> Craig McQueen
>
>
> I found that a very basic Python program that does nothing except `import
> threading` causes this message.
>
> (I had hoped that `import threading` in the main program might be a
> work-around, after reading the comments on the Python bug report linked
> above. My program originally didn't import threading directly, but evidently
> uses it indirectly for win32com COM client programming.)
>
> Regards,
> Craig McQueen
>
> I looked at the source code, and found that in the initscripts/Console.py--
> http://cx-freeze.svn.sourceforge.net/viewvc/cx-freeze/trunk/initscripts/Console.py?revision=205&view=markup
>
> --there are the following lines:
>
>     if sys.version_info[:2] >= (2, 5):
>         module = sys.modules.get("threading")
>         if module is not None:
>             module._shutdown()
>
> If these lines are commented-out, then the error message at exit does not
> occur.
>
> Why are those lines there, and what is the consequence of me removing them?

Hi Craig,

The reason those lines are there is because without them any threads
that are currently running will simply die when the application ends.
The Python interpreter itself calls an internal routine that waits for
the threads to terminate on their own. Its unfortunate that this isn't
included inside Py_Finalize() but its not. Before Python 2.5, this was
done via means of an atexit function (which happened inside
Py_Finalize) but with Python 2.5 and up this has been changed to call
a special function within the main routine of the Python interpreter.
I have replicated the behavior using the above lines and that has
worked for me for some time. Would you be able to send me a sample
program that I can run and that demonstrates the problem? Thanks.

Anthony

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
cx-freeze-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cx-freeze-users

Reply via email to