Ver Fonte

Abstract the API even more into childutils.

Chris McDonough há 17 anos atrás
pai
commit
3eca4429d1

+ 6 - 0
src/supervisor/childutils.py

@@ -65,6 +65,12 @@ def eventdata(payload):
     return headers, data
 
 class EventListenerProtocol:
+    def wait(self):
+        self.ready()
+        line = sys.stdin.readline()
+        headers = get_headers(line)
+        payload = sys.stdin.read(int(headers['len']))
+        return headers, payload
     def ready(self):
         write_stdout(PEventListenerDispatcher.READY_FOR_EVENTS_TOKEN)
     def ok(self, *ignored):

+ 1 - 4
src/supervisor/scripts/loop_listener.py

@@ -25,10 +25,7 @@ from supervisor import childutils
 def main():
     rpcinterface = childutils.getRPCInterface(os.environ)
     while 1:
-        childutils.protocol.ready()
-        line = sys.stdin.readline()
-        headers = childutils.get_headers(line)
-        payload = sys.stdin.read(int(headers['len']))
+        headers, payload = childutils.protocol.wait()
         if headers['eventname'].startswith('PROCESS_COMMUNICATION'):
             pheaderinfo, pdata = payload.split('\n')
             pheaders = childutils.get_headers(pheaderinfo)

+ 1 - 4
src/supervisor/scripts/osx_memmon_listener.py

@@ -43,10 +43,7 @@ except ImportError:
 def main(maxkb):
     rpc = childutils.getRPCInterface(os.environ)
     while 1:
-        childutils.protocol.ready()
-        line = sys.stdin.readline()
-        headers = childutils.get_headers(line)
-        payload = sys.stdin.read(int(headers['len']))
+        headers, payload = childutils.protocol.wait()
         if headers['eventname'].startswith('PROCESS_COMMUNICATION'):
             pheaders, pdata = childutils.eventdata(payload)
             procname, groupname = pheaders['processname'], pheaders['groupname']

+ 6 - 1
src/supervisor/scripts/sample_eventlistener.py

@@ -16,7 +16,12 @@
 
 # A sample long-running supervisor event listener which demonstrates
 # how to accept event notifications from supervisor and how to respond
-# properly
+# properly.  This demonstration does *not* use the
+# supervisor.childutils module, which wraps the specifics of
+# communications in higher-level API functions.  If your listeners are
+# implemented using Python, it is recommended that you use the
+# childutils module API instead of modeling your scripts on the
+# lower-level protocol example below.
 
 import sys
 

+ 10 - 3
src/supervisor/scripts/sample_exiting_eventlistener.py

@@ -14,9 +14,16 @@
 #
 ##############################################################################
 
-# A sample supervisor event listener which demonstrates how to accept
-# event notifications from supervisor and how to respond properly,
-# exiting after each event is accepted and processed
+# A sample long-running supervisor event listener which demonstrates
+# how to accept event notifications from supervisor and how to respond
+# properly.  It is the same as the sample_eventlistener.py script
+# except it exits after each request (presumably to be restarted by
+# supervisor).  This demonstration does *not* use the
+# supervisor.childutils module, which wraps the specifics of
+# communications in higher-level API functions.  If your listeners are
+# implemented using Python, it is recommended that you use the
+# childutils module API instead of modeling your scripts on the
+# lower-level protocol example below.
 
 import sys