471,353 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,353 software developers and data experts.

Pythonw.exe exits prematurely

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

Oct 23 '07 #1
3 3462
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:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2.  
  3. f2 = open("bo.err", "w")
  4. sys.stderr = f2
  5. for i in range(10000):
  6. print i
  7.  
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.

Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import os
  3.  
  4. nul = open(sys.devnull,'w')
  5. sys.stdout = nul
  6. sys.stderr = nul
  7.  
  8. # The rest of your code
  9.  
Matt

Oct 23 '07 #2
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...@gmail.comwrote:
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:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. f2 = open("bo.err", "w")
  3. sys.stderr = f2
  4. for i in range(10000):
  5.     print i
  6.  

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.

Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import os
  3. nul = open(sys.devnull,'w')
  4. sys.stdout = nul
  5. sys.stderr = nul
  6. # The rest of your code
  7.  

Matt

Oct 24 '07 #3

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...@gmail.comwrote:
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:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. f2 = open("bo.err", "w")
  3. sys.stderr = f2
  4. for i in range(10000):
  5.     print i
  6.  

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.

Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import os
  3. nul = open(sys.devnull,'w')
  4. sys.stdout = nul
  5. sys.stderr = nul
  6. # The rest of your code
  7.  

Matt

Oct 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by ..:: sjf ::.. | last post: by
3 posts views Thread by vm_usenet | last post: by
5 posts views Thread by Robin Becker | last post: by
1 post views Thread by Jo Schambach | last post: by
1 post views Thread by Randy Harris | last post: by
1 post views Thread by Roger Miller | last post: by
5 posts views Thread by Ron Garret | last post: by
3 posts views Thread by John Velman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.