Pythonw.exe exits prematurely

Brainsludge brainsludge at gmail.com
Tue Oct 23 21:59:20 EDT 2007


The script has been running console-free for about an hour now without
bailing. Looks like it was the stdout buffer.

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