RE: python.exe vs pythonw.exe difference?

From: Tim Peters (tim_at_zope.com)
Date: 03/02/04


Date: Tue, 2 Mar 2004 10:50:21 -0500
To: <zope-dev@zope.org>


[moving this from comp.lang.python to zope-dev; it really belongs on a
 Zope list, although schemes to change what pythonw does probably belong
 on python-dev]

[Emile van Sebille <emile@fenx.com>]
>> I've possibly narrowed a problem I'm having running zope as a service
>> on winxp pro sp 1 in that when started from a command line as:
>>
>> c:\zope\v27\lib\python\python.exe \
         c:\zope\v27\lib\python\zope\startup\run.py -C \
         c:\zope\v27\instance\etc\zope.conf

[tim inserted backslashes above, to make the line structure clear]

>> it starts up just fine (although now running from the console).
>>
>> But when I start it with:
>>
>> c:\zope\v27\lib\python\pythonw.exe \
         c:\zope\v27\lib\python\zope\startup\run.py -C \
         c:\zope\v27\instance\etc\zope.conf
>>
>> it dies after about 30 seconds.
>>
>> It wouldn't surprise me that I'm doing something it doesn't like (I'm
>> spawning additional processes from within a product but it worked
>> fine with 2.5),

It's unclear what "it" means, in "it wworked fine with 2.5". For example,
do you mean that the second command line, using pythonw.exe explicitly from
a DOS box worked fine, or do you mean that running Zope as a service on XP
Pro SP1 worked fine, or ...?

>> but I'm somewhat at a loss as to debugging it in> that when run as a
>> console app it works fine, but when run windowless it doesn't.

Did you look in your Zope log file(s) for tracebacks?

>> Do I have to write out check points to a file? or is there some way
>> to use Mark Hammonds process debugging tools? Or is this a bug,
>> known or otherwise?

[Thomas Heller]
> It has been reported that writing to the original sys.stdout (and
> maybe also sys.stderr) sooner or later raises an IOError when running
> pythonw.exe, unless these are redirected. Could this be the problem?

It could, although I have no idea what WinXP does (and don't have access to
XP). Here's a Python program to try:

"""
import sys
if 1: # edit to 1 for stdout, 0 for stderr
    console = sys.stdout
else:
    console = sys.stderr

import traceback
tb = file('tb.txt', 'w')

try:
    i = 0
    while True:
        i += 1
        console.write('.')
except:
    print >> tb, "Died when trying to write byte", i
    traceback.print_exc(file=tb)
    tb.close()
"""

Under Win98SE, and regardless of whether it writes to stdout or stderr, it
dies when run under pythonw, and tb.txt contains this after:

Died when trying to write byte 4097
Traceback (most recent call last):
  File "wr.py", line 14, in ?
    console.write('.')
IOError: [Errno 9] Bad file descriptor

The point of pythonw.exe is that no console is created or inherited, and the
default stdin, stdout and stderr provided by MS C in that case are unusable
(although the output flavors can appear to be usable until some secret MS
limit is exceeded -- at least under Win98SE).



Relevant Pages

  • Re: python.exe vs pythonw.exe difference?
    ... although schemes to change what pythonw does probably belong ... > console = sys.stdout ... > Traceback: ... stdout and stderr provided by MS C in that case are unusable ...
    (comp.lang.python)
  • Re: Help running pythonw from a command prompt with arguments
    ... CREATE stdio window vs "pythonw" suppressing that window. ... Since you already have a console window the use of "pythonw" is ... "pythonw" would suppress the window expecting the program to ...
    (comp.lang.python)
  • Re: python.exe vs pythonw.exe difference?
    ... "Tim Peters" writes: ... > hand from a DOS box with pythonw used to work, ... > Zope tries to live with Windows services. ... the bit bucket is full. ...
    (comp.lang.python)
  • Re: python vs pythonw
    ... Both python and pythonw run it, ... python runs in console mode (and pops up a console window ... runs the script as a background process. ...
    (comp.lang.python)
  • Re: BUG pythonw vs subprocess
    ... I thought pythonw didn't provide a console and so it could be that ... stdin and stdout aren't connected to anything. ...
    (comp.lang.python)