[python-win32] Runnin Python app as service with separate console

Waldemar Osuch waldemar.osuch at gmail.com
Fri Apr 7 04:14:51 CEST 2006


On 4/6/06, Michael Li <mli at deform.com> wrote:
>  > Although it is not obvious from Twisted documentation it is trivial to
>  > run an application as a windows service as long as you use *.tac files
>  > to build it.
>
> Can you share your code ?
>
> I also have an application using Twisted, but I got problems to run as a
> service.

I am using py2exe with custom setup.py file.
Additionally I have startup.tac and winservice.py
 - startup.tac - if you know Twisted then you know what goes into
startup.tac :-).
 - winservice.py - is the stub file that gets compiled into
winservice.exe.  This is the file that you will register with Windows.
 winservice.exe -h will list all the options.  I do not remember them
at them moment.
 - setup.py - is almost standard setup file.  You run it with python
setup.py py2exe.  The trick is to list all required modules
explicitly.  I list all except the modules that hold my Twisted
application logic. The advantage is that I can replace the modules
without recompiling.  Only restart the service and the bug fix is
implemented.  Your admin will love you for that :-)
The only problem is if you missed a required module the service will
die silently when starting.  Luckily the Python traceback gets
recorded in Windows Application Log.
Check it to see what the service is complaining about, add the missing
part, rinse and repeat.

See the attached files for an example.
The original idea comes from:
http://twistedmatrix.com/trac/browser/sandbox/moonfallen/
See it for more documentation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winservice.py
Type: text/x-python
Size: 1580 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-win32/attachments/20060406/008105d3/attachment-0002.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: startup.tac
Type: application/octet-stream
Size: 1827 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-win32/attachments/20060406/008105d3/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setup.py
Type: text/x-python
Size: 2025 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-win32/attachments/20060406/008105d3/attachment-0003.py 


More information about the Python-win32 mailing list