[Twisted-Python] More about twistd and win32 service
![](https://secure.gravatar.com/avatar/2f626ca5650f292f76a9513531228a45.jpg?s=120&d=mm&r=g)
Itamar and others, Sorry for the delayed reply and thank you for your constant help. I setup my NT service as you described, importing the win32eventreactor and installing it. The service starts up fine, but when I stop the service I get the following in the logs. The "15:08 ... Unexpected..." entry only gets dumped in the log when stopping the service. I'm not sure how I'd go about debugging this more since I can't get anymore output than what's dumped to the log. Any ideas? I've attached winsvc.py and a couple other files it is dependent on. Thanks again. -Justin 2003/10/30 15:07 Eastern Standard Time [-] Log opened. 2003/10/30 15:07 Eastern Standard Time [-] twisted.spread.pb.PBServerFactory starting on 8787 2003/10/30 15:07 Eastern Standard Time [-] Starting factory <twisted.spread.pb.PBServerFactory instance at 0x00DF8D28> 2003/10/30 15:08 Eastern Standard Time [-] Unexpected error in main loop. 2003/10/30 15:08 Eastern Standard Time [-] Traceback (most recent call last): File "E:\Python22\Lib\site-packages\win32\lib\win32serviceutil.py", line 635, in SvcRun self.SvcDoRun() File "E:\ccase\python\winsvc.py", line 24, in SvcDoRun reactor.run() File "E:\Python22\Lib\site-packages\twisted\internet\default.py", line 122, in run self.mainLoop() --- <exception caught here> --- File "E:\Python22\Lib\site-packages\twisted\internet\default.py", line 133, in mainLoop self.doIteration(t) File "E:\Python22\Lib\site-packages\twisted\internet\win32eventreactor.py", line 180, in doWaitForMultipleEvents fd, action = events[handles[val - WAIT_OBJECT_0]] exceptions.KeyError: <PyHANDLE:224> ----- Original message ----- From: "Itamar Shtull-Trauring" <itamar@itamarst.org> To: twisted-python@twistedmatrix.com Date: Wed, 22 Oct 2003 14:50:10 -0400 Subject: Re: [Twisted-Python] twistd and win32 service On Wed, 22 Oct 2003 12:24:42 -0600 "Justin Johnson" <justinjohnson@fastmail.fm> wrote:
Uh. *Maybe* that's the consensus, but it's not actually correct. You can have a tap or tac run as a NT service. Lets say you have a script "server.py" that is runnable with "twistd -y", you can do (and similar code will work for TAPs): import sys, os import win32serviceutil, win32service class MyService(win32serviceutil.ServiceFramework): """NT Service.""" _svc_name_ = "MyService" _svc_display_name_ = "MyService server" def SvcDoRun(self): import server f = open(os.path.join(server.rootPath, "cyberhigh.log"), 'a') from twisted.python.log import startLogging from twisted.application.app import startApplication from twisted.internet import reactor startLogging(f) startApplication(server.application, 0) reactor.run() def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) from twisted.internet import reactor reactor.stop() if __name__ == '__main__': win32serviceutil.HandleCommandLine(MyService) -- Itamar Shtull-Trauring http://itamarst.org/ Available for Python & Twisted consulting _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Fri, 31 Oct 2003 08:31:30 -0600 "Justin Johnson" <justinjohnson@fastmail.fm> wrote:
Looks like a bug in the win32event reactor - add it to the tracker? -- Itamar Shtull-Trauring http://itamarst.org/ Available for Python & Twisted consulting
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Fri, 31 Oct 2003 08:31:30 -0600 "Justin Johnson" <justinjohnson@fastmail.fm> wrote:
Looks like a bug in the win32event reactor - add it to the tracker? -- Itamar Shtull-Trauring http://itamarst.org/ Available for Python & Twisted consulting
participants (2)
-
Itamar Shtull-Trauring
-
Justin Johnson