Pythonw.exe exits prematurely

Brainsludge brainsludge at gmail.com
Tue Oct 23 20:07:15 EDT 2007


Hi Matt,

Your reply is much appreciated.

So let me see if I understand. When console is running, it dumps
stdout to console, the buffer is flushed regularly, and everything is
fine and dandy. But when running without console, the stdout buffer
fills up because it has no physical handle to dump to, an exception is
thrown, and the process bails.

The graceful exit I mentioned before (the cleanup routine) was likely
due to a try/except I wrapped around the polling loop that handled the
exception you described.

I'll give it a try. Thanks!
Brian

On Oct 23, 4:43 pm, Matimus <mccre... at gmail.com> wrote:
> > I am running WinXP SP2 with Python 2.5.1 and encountered the following
> > issue:
>
> > I wrote a script that logs into my mail server, and checks for new
> > messages every 20 seconds. When a new message is found, it displays a
> > Windows tool tip and prints a line to console indicating a new
> > message.
>
> > When I run the script with python.exe (console), the script runs fine
> > and checks for new messages in perpetuity (as it should). However,
> > when I run the script with pythonw.exe (no console), the script
> > prematurely exits after 10 or 15 minutes. For those 15 minutes, it
> > works as it should, displaying tool tips when new messages arrive.
> > Furthermore, when it exits prematurely, it appears to be exiting
> > gracefully (I have an exit routine that logs out of the mail server
> > and cleans up).
>
> > Does anyone know why this might be the case? The lines printed to
> > console are purely for diagnostic purposes. Otherwise, the two
> > processes should be identical.
>
> You say it exits gracefully, I'm not sure I know what you mean. My
> guess is that you are writing to stdout, and when the buffer fills up
> and tries to dump the program exits with an exception (but returns
> 0).
>
> I've run into something similar before, you can reproduce it with
> this:
> [code]
> import sys
>
> f2 = open("bo.err", "w")
> sys.stderr = f2
> for i in range(10000):
>     print i
> [/code]
>
> Run with pythonw then look at "bo.err" to see the exception.
>
> You can either stop printing to stdout and send the stuff somewhere
> else (maybe use the logging module), or you can assign stdout and
> stderr to nul.
>
> [code]
> import sys
> import os
>
> nul = open(sys.devnull,'w')
> sys.stdout = nul
> sys.stderr = nul
>
> # The rest of your code
> [/code]
>
> Matt





More information about the Python-list mailing list