[Zope-Checkins] CVS: Zope/lib/python/nt_svcutils - service.py:1.4.2.3

Jeremy Hylton jeremy at zope.com
Mon Jan 26 15:57:19 EST 2004


Update of /cvs-repository/Zope/lib/python/nt_svcutils
In directory cvs.zope.org:/tmp/cvs-serv26606/Zope/lib/python/nt_svcutils

Modified Files:
      Tag: jeremy-windows-service-branch
	service.py 
Log Message:
Use the win32 api directly for readng from pipe.

The open_osfhandle() failed after the first process restart for mysterious reasons.  It appeared that one of the file handles (pipes) was getting reused, causing open_osfhandle() to fail thinking that the handle wasn't valid.  That problem could be worked around by opening extra, unused pipes after a CreateProcess, but that's no solution.


=== Zope/lib/python/nt_svcutils/service.py 1.4.2.2 => 1.4.2.3 ===
--- Zope/lib/python/nt_svcutils/service.py:1.4.2.2	Mon Jan 26 12:22:28 2004
+++ Zope/lib/python/nt_svcutils/service.py	Mon Jan 26 15:57:18 2004
@@ -139,7 +139,7 @@
             info, handles = self.createProcess(self.start_cmd)
             # XXX integrate handles into the wait and make a loop
             # that reads data and writes it into a logfile
-            self.hZope = info[0] # the pid
+            self.hZope = info[0] # process handle
             # XXX why the test before the log message?
             if self.backoff_interval > BACKOFF_INITIAL_INTERVAL:
                 self.info("created process")
@@ -158,14 +158,7 @@
 
         keep_running = True
         # ignore stdin
-        print "stdin=%s stdout=%s stderr=%s" % handles
-        win32file.CloseHandle(handles[0])
-        fd = msvcrt.open_osfhandle(handles[1], 0)
-        stdout = os.fdopen(fd)
-        fd = msvcrt.open_osfhandle(handles[2], 0)
-        stderr = os.fdopen(fd)
-##        stdout = os.fdopen(msvcrt.open_osfhandle(handles[1], 0))
-##        stderr = os.fdopen(msvcrt.open_osfhandle(handles[2], 0))
+        handles[0].Close()
 
         while 1:
             rc = win32event.WaitForMultipleObjects(
@@ -187,15 +180,23 @@
             else:
                 i = rc - (win32event.WAIT_OBJECT_0 + 2)
                 if i == 0:
-                    data = stdout.read(8192)
+                    try:
+                        ec, data = win32file.ReadFile(handles[1], 8192)
+                    except pywintypes.error, err:
+                        print err
+                        continue
                     if data:
                         self.info("stdout: %s" % data)
                 elif i == 1:
-                    data = stderr.read(8192)
+                    try:
+                        ec, data = win32file.ReadFile(handles[2], 8192)
+                    except pywintypes.error, err:
+                        print err
+                        continue
                     if data:
                         self.info("stderr: %s" % data)
-        stdout.close()
-        stderr.close()
+        handles[1].Close()
+        handles[2].Close()
         return keep_running
 
     def checkRestart(self):
@@ -264,3 +265,4 @@
 
 if __name__ == '__main__':
     win32serviceutil.HandleCommandLine(Service)
+




More information about the Zope-Checkins mailing list