durusmail: quixote-users: Need help in running quixote.demo as medusas' ortwisteds' win32 service
Need help in running quixote.demo as medusas' or twisteds' win32 service
2004-03-29
Need help in running quixote.demo as medusas' ortwisteds' win32 service
2004-03-29
Need help in running quixote.demo as medusas' ortwisteds' win32 service
2004-03-29
Re: Need help in running quixote.demo as medusas' or twisteds' win32 service
2004-03-29
Re: Need help in running quixote.demo as medusas' or twisteds' win32 service
2004-03-29
Re: Need help in running quixote.demo as medusas' or twisteds' win32 service
2004-03-29
2004-03-29
Need help in running quixote.demo as medusas' ortwisteds' win32 service
Jason E. Sibre
2004-03-29
Samir,

You've got something going on that I'm not too familiar with (running Medusa
as a service in Windows)...

Two things come to mind, though, as I look at your traceback, and the code
in asyncore...
 * Does a 'Service' in win32 have a stdout?  I don't know, but I'm pretty
sure the answer is "No," based on the error you're getting, a hunch, and the
link I've attached below.
 * The 'logging' being done by asyncore is using the print statement.  As
you probably know/recall, Quixote replaces sys.stdout (the 'file' all print
statements write to) with your debug file.  Did you define a debug file?  If
not, that print will still go to the real STDOUT, which, since this is a
Service, probably doesn't exist.  If you haven't done so already, try
defining a debug file in your quixote conf file to catch the STDOUT stuff.

In trying to find out about the Service / STDOUT issue (to confirm my hunch)
I found this, which may help in a couple of ways:
http://twistedmatrix.com/pipermail/twisted-python/2001-December/000644.html

Quoting the relevant part:
>  Andrew Bennetts said:> The trickiest bit is that you need to set the log
> file to something other than stdout, otherwise it dies due to a Bad File
> Descriptor error doing logfile.flush().  Other than that, it is
> basically boilerplate code (if you're familiar with Win32 services
> written in Python).
But you'll probably want to read the whole post, as it relates to getting
Twisted to run as a service.Good luck!Jason

 -----Original Message-----
From: quixote-users-bounces+jsibre=chironsys.com@mems-exchange.org
[mailto:quixote-users-bounces+jsibre=chironsys.com@mems-exchange.org]On
Behalf Of Samir Patel
Sent: Sunday, March 28, 2004 9:37 PM
To: quixote-users@mems-exchange.org
Subject: [Quixote-users] Need help in running quixote.demo as medusas'
ortwisteds' win32 service


  I have created a quixote program which I like to run as service on windows
machine using either medusa or twisted matrix as web server.
  I am having trouble with both of them. Am I missing something or I have to
run it with IIS or Apache?



  When I run quixote.demo (quixote 0.7a3) with medusa server as a win32
service as follows:

  import win32serviceutil
  import win32service
  import win32event

  class motorService(win32serviceutil.ServiceFramework):
      _svc_name_ = "motorService"
      _svc_display_name_ = "The Motor Service"
      def __init__(self, args):
          win32serviceutil.ServiceFramework.__init__(self, args)
          #self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

      def SvcStop(self):
          pass
         # self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
         # win32event.SetEvent(self.hWaitStop)

      def SvcDoRun(self):
          import asyncore
          from quixote.server.medusa_http import http_server, QuixoteHandler
          from quixote import enable_ptl
          from quixote.publish import Publisher
          enable_ptl()
          server = http_server.http_server('', 80)

          publisher = Publisher('quixote.demo')
          publisher.setup_logs()
          dh = QuixoteHandler(publisher, 'Quixote/demo', server)
          server.install_handler(dh)
          asyncore.loop()

          #win32event.WaitForSingleObject(self.hWaitStop,
win32event.INFINITE)

  if __name__=='__main__':
      win32serviceutil.HandleCommandLine(motorService)

  **********************************************
  It runs for some time and then stop running with following error in
eventlog:

  Event Type: Error
  Event Source: Python Service
  Event Category: None
  Event ID: 3
  Date:  3/28/2004
  Time:  10:20:51 PM
  User:  N/A
  Computer: RCPORTABLE
  Description:
  The instance's SvcRun() method failed
    File "C:\Python23\lib\site-packages\win32\lib\win32serviceutil.py", line
670, in SvcRun
      self.SvcDoRun()
    File "C:\Python23\service\motorServiceMedusa.py", line 29, in SvcDoRun
      asyncore.loop()
    File "C:\Python23\lib\asyncore.py", line 193, in loop
      poll_fun(timeout, map)
    File "C:\Python23\lib\asyncore.py", line 125, in poll
      write(obj)
    File "C:\Python23\lib\asyncore.py", line 81, in write
      obj.handle_error()
    File "c:\python23\Lib\site-packages\medusa\http_server.py", line 429, in
handle_error
      asynchat.async_chat.handle_error (self)
    File "C:\Python23\lib\asyncore.py", line 418, in handle_error
      'error'
    File "C:\Python23\lib\asyncore.py", line 376, in log_info
      print '%s: %s' % (type, message)
  exceptions.IOError: (9, 'Bad file descriptor')



****************************************************************************
**********************

  When I run with twisted as follows:

  import win32serviceutil
  import win32service
  import win32event

  class motorService(win32serviceutil.ServiceFramework):
      _svc_name_ = "motorService"
      _svc_display_name_ = "The Motor Service"
      def __init__(self, args):
          win32serviceutil.ServiceFramework.__init__(self, args)
          #self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

      def SvcStop(self):
          pass
         # self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
         # win32event.SetEvent(self.hWaitStop)

      def SvcDoRun(self):
          from twisted.internet.app import Application
          from quixote.server.twisted_http import QuixoteFactory
          import quixote
          quixote.enable_ptl()
          from quixote.publish import Publisher
          from twisted.python.log import startLogging
          startLogging(open('c:/twistedexample.log','a'))

          import quixote.demo
          http_port = 80
          namespace = quixote.demo

          app = Application('Quixote')
          publisher = Publisher(namespace)
          qf = QuixoteFactory(publisher)
          app.listenTCP(http_port, qf)
          app.run(save=0)


  I got following error in twisted log file. I can not run demo at all using
twisted.

  2004/03/28 22:19 Eastern Standard Time [-] Log opened.
  2004/03/28 22:19 Eastern Standard Time [-]
C:\Python23\service\motorService.py:30: exceptions.DeprecationWarning:
twisted.internet.app is deprecated, use twisted.application or the reactor
instead.
  2004/03/28 22:19 Eastern Standard Time [*Quixote*]
quixote.server.twisted_http.QuixoteFactory starting on 80
  2004/03/28 22:19 Eastern Standard Time [*Quixote*] Starting factory

  2004/03/28 22:19 Eastern Standard Time [*Quixote*] Traceback (most recent
call last):
     File "C:\Python23\lib\site-packages\win32\lib\win32serviceutil.py",
line 670, in SvcRun
       self.SvcDoRun()
     File "C:\Python23\service\motorService.py", line 34, in SvcDoRun
       app.run(save=0)
     File "C:\Python23\Lib\site-packages\twisted\internet\app.py", line 873,
in run
       log.callWithLogger(self, reactor.run,
installSignalHandlers=installSignalHandlers)
   ---  ---
     File "C:\Python23\Lib\site-packages\twisted\python\log.py", line 65, in
callWithLogger
       callWithContext({"system": lp}, func, *args, **kw)
     File "C:\Python23\Lib\site-packages\twisted\python\log.py", line 52, in
callWithContext
       return context.call({ILogContext: newCtx}, func, *args, **kw)
     File "C:\Python23\Lib\site-packages\twisted\python\context.py", line
32, in callWithContext
       return func(*args,**kw)
     File "C:\Python23\Lib\site-packages\twisted\internet\default.py", line
124, in run
       self.startRunning(installSignalHandlers=installSignalHandlers)
     File "C:\Python23\Lib\site-packages\twisted\internet\default.py", line
120, in startRunning
       self._handleSignals()
     File "C:\Python23\Lib\site-packages\twisted\internet\default.py", line
92, in _handleSignals
       signal.signal(signal.SIGINT, self.sigInt)
   exceptions.ValueError: signal only works in main thread




reply