[python-win32] problems when running python script from windows service app

Damian Okrasa dokrasa at gmail.com
Fri Jun 11 15:08:23 CEST 2010


2010/6/11 Mark Hammond <skippy.hammond at gmail.com>:
> On 10/06/2010 9:28 PM, Damian Okrasa wrote:
>>
>> I'm using Python 3.1.2 on Windows 7. I have windows service written in
>> C which starts python script and it doesn't work. However when C
>> program isn't windows service it works flawlessly.
>
> Why not just implement the service directly in Python?
>

I don't know if I could. I have everything in one directory, so
installing python won't be required. The service only sets current
working directory to directory where service exe and python dll are,
and then it starts python application.

>> // log.txt
>> <class 'AttributeError'>("'NoneType' object has no attribute
>> 'write'",)'NoneType' object has no attribute 'write'
>
> You need to get the full traceback - I suspect the problem is that something
> is attempting to write to sys.stderr or sys.stdout, but these will be None
> in py3k when there is no console attached.
>
> Cheers,
>
> Mark
>

I checked the traceback and the last log lines were:

File "C:\Python31\Lib\http\server.py", line 464, in log_message
    sys.stderr.write("%s - - [%s] %s\n" %
AttributeError: 'NoneType' object has no attribute 'write'

So you were right. It worked when I added:

f = open("c:\\stderr.txt", "w")
sys.stderr = f


More information about the python-win32 mailing list