[Twisted-Python] Running twistd and tac files as Windows service
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Tue Oct 23 05:41:19 MDT 2012
On 08:23 am, johnaherne at rocs.co.uk wrote:
>I have been looking at running some twisted programs as a windows
>service.
>
>So in the end I took a copy of twistd.py and adapted it to load my tac
>file
>and run it as a windows service.
>
>Of course the windows service will run it in a separate thread.
>
>I now have it running on XP, 2003 Server Twisted 10 and 12 and it all
>seemed fine.
To start off with, I'll point out that this isn't a supported mode of
running Twisted (which I'm sure you noticed already :).
This feature has been requested several times and worked on by a couple
people, but not quite to the point of completion.
Here's a related ticket:
http://twistedmatrix.com/trac/ticket/4073
There's also some more code in the sandbox:
http://twistedmatrix.com/trac/browser/sandbox/moonfallen
BuildBot also has some code, though I'm not exactly sure where it is.
It would be really great for someone to actually complete and generalize
one or more of these initial attempts so that Windows service
integration could be a real, working feature. :)
>However when I install it on Windows 7 I get an error
>
>2012-10-23 07:54:49+0100 [-] Unhandled Error
>Traceback (most recent call last):
> File "C:\Python27\lib\site-packages\twisted\internet\base.py", line
>413,
>in fireEvent
> DeferredList(beforeResults).addCallback(self._continueFiring)
> File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line
>297,
>in addCallback
> callbackKeywords=kw)
> File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line
>286,
>in addCallbacks
> self._runCallbacks()
> File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line
>542,
>in _runCallbacks
> current.result = callback(current.result, *args, **kw)
>--- <exception caught here> ---
> File "C:\Python27\lib\site-packages\twisted\internet\base.py", line
>426,
>in _continueFiring
> callable(*args, **kwargs)
> File "C:\Python27\lib\site-packages\twisted\internet\base.py", line
>1153,
>in _reallyStartRunning
> self._handleSignals()
> File "C:\Python27\lib\site-packages\twisted\internet\posixbase.py",
>line
>277, in _handleSignals
> _SignalReactorMixin._handleSignals(self)
> File "C:\Python27\lib\site-packages\twisted\internet\base.py", line
>1118,
>in _handleSignals
> signal.signal(signal.SIGINT, self.sigInt)
>exceptions.ValueError: signal only works in main thread
>
>
>Looking around it would seem I need to tell the reactor
>'installsignalhandlers=0'. I am not sure if I should do this with
>windows
>or not.
Yes, you'll need to do that. It probably won't even break child process
support (although other aspects of Windows services probably will).
Notice it's failing on installing a SIGINT handler - ie, a Control-C
handler. Since you want the thing to run as a service, you probably
aren't very interested in having Control-C do anything.
Jean-Paul
>Has anyone got twistd.py to run as a service on windows because I would
>be
>glad to know what other people have done to solve the problem.
>
>Thanks for any info.
>
>*John Aherne*
More information about the Twisted-Python
mailing list