high wisdom



Thu Feb 11 13:08:49 IST 2010

Debugging python Windows services

Python makes it easy to write Windows services (via pywin32 extensions). That part is easy. The problems sometimes happen when you try to run them, with a commonly reported error - "The service did not respond to the control...", which is error 1503.

If one runs the service compiled as an exe (via py2exe for example), there are a bunch of issues like the module import paths changing. I haven't had the time to dig really deep into that. But this might strike even if the service is being run uncompiled (from a .py file).

One of the first things to check is whether pythonservice.exe (from the win32 module) executes cleanly - this is the binary responsible for actually loading your service script/module. If pywin32 was installed in the usual way, it should be located at C:\Python26\Lib\site-packages\win32\pythonservice.exe

Running this should give an immediate idea of what's going wrong. It usually turns out to be a "msvcr90.dll" or a "python26.dll" error. (Of course, all this is Python 2.6). When that is running alright, then it's time for some debug fun.

To debug the python service, just run pythonservice.exe with the '-debug' option and the service name as the argument. This attaches the stdout/stderr to the terminal. For example, if the service uses BaseHTTPServer, all the request/response logs will show up.


Posted by gera | Permanent link | File under: tricks | [ hide comments ]
Add comment here
name:
e-mail:
website:
spam-protection, please enter code: captcha, sorry
comment:

remember me
request e-mail if someone adds comments
Your e-Mail will not be published,
http://www.URL.com will turn to link automatically,
html is not permitted