Pythonw.exe exits prematurely

B

Brainsludge

Hello,

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.

Thanks!
Brian
 
M

Matimus

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

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

Matt
 
B

Brainsludge

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

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

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

Matt
 
B

Brainsludge

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

Thanks!
Brian

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

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

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top