[Twisted-Python] How to run Twisted as a service in Windows?
Thomas Jacob
jacob at internet24.de
Wed Aug 9 10:49:30 EDT 2006
AFAIK, twistd doesn't provide direct support for Windows Services yet
(Is this planned?).
But you can easily wrap a reactor,run() yourself by doing something
like the following using the Win32-Python packages
import win32serviceutil
import win32service
import win32event
from twisted.internet import reactor
import sys
class IMSAgentBase(win32serviceutil.ServiceFramework):
_svc_name_ = "myService"
_svc_display_name_ = "My little Service"
_svc_description_ = "My little Service" # Win2k or later
_svc_deps_ = ["RpcSs"] # Start after the Network has come up...
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
reactor.callFromThread(reactor.stop)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
# initialize your services here
reactor.run()
win32event.WaitForSingleObject(self.hWaitStop,
win32event.INFINITE)
def HandleCommandLine(cls):
win32serviceutil.HandleCommandLine(cls)
Run the above as a script.
Maybe you also want to buy the following book, the docs on Python Win32
are somewhat sparse....
"Python Programming on WIN32 (Paperback)"
http://www.amazon.com/gp/product/1565926218
On Wed, 2006-08-09 at 10:06 -0400, Mona Yazbeck wrote:
> Hello,
>
> I am on Windows, and I have Python 2.4
>
> I am starting twisted with twistd.py for my wiki, but it opens a
> command prompt so as soon as I log off the server it is no longer
> working and if I restart it is the same thing. How can I run it as a
> service so it will always be up?
>
> I don't know much about twisted I just installed it with the MSI and
> follow 2 or 3 instructions from MoinMoin website (the wiki).
>
> Thanks
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20060809/b72608f7/attachment.pgp
More information about the Twisted-Python
mailing list