drop unused event id from spawn_child
authorHelmut Grohne <helmut@subdivi.de>
Wed, 12 Mar 2014 21:18:29 +0000 (22:18 +0100)
committerHelmut Grohne <helmut@subdivi.de>
Wed, 12 Mar 2014 21:18:29 +0000 (22:18 +0100)
onoff/command.py
onoff/gobject.py
onoff/process.py

index f1b9021..d9b12c0 100644 (file)
@@ -11,8 +11,6 @@ class OnoffCommand(OnoffDevice):
     @type pid: int or None
     @ivar pid: is either None or the pid of a transition command as long as
             it lives.
-    @ivar watch: is either None or a GObject event source id of the
-            callback waiting for the termination of the spawned process.
     @type desired_state: bool
     @ivar desired_state: is the state that should be transitioned to
     @type target_state: bool
@@ -33,7 +31,6 @@ class OnoffCommand(OnoffDevice):
         self.offcommand = offcommand
         self.desired_state = 0 # bit mask of just ST_ACTIVE
         self.pid = None
-        self.watch = None
         self.target_state = 0 # state the last command targeted
 
     @property
@@ -47,14 +44,12 @@ class OnoffCommand(OnoffDevice):
                          (self.oncommand, "oncommand")][state]
         self.target_state = state
         logger.info("invoking %s %s", name, " ".join(command))
-        self.pid, self.watch = spawn_child(command, self.process_died)
+        self.pid = spawn_child(command, self.process_died)
         logger.debug("started %s as pid %d", name, self.pid)
         self.changestate(self.state)
 
     def process_died(self, pid, condition):
         assert self.pid == pid
-        assert self.watch is not None
-        self.watch = None
         self.pid = None
         logger.info("command %d targeting %d completed", pid, self.target_state)
         if self.desired_state == self.target_state:
index 8c52221..73ed7d2 100644 (file)
@@ -9,12 +9,12 @@ def spawn_child(command, callback):
             used as executable to look up in $PATH.
     @type callback: (pid, condition) -> None
     @param callback: is executed when the command completes
-    @rtype: (int, int)
-    @returns: the child process pid and the event id of the callback
+    @rtype: int
+    @returns: the child process pid
     """
     ret = GObject.spawn_async(command,
             flags=GObject.SPAWN_SEARCH_PATH | GObject.SPAWN_DO_NOT_REAP_CHILD)
     pid = ret[0]
     assert pid
-    watch = GObject.child_watch_add(pid, callback)
-    return pid, watch
+    GObject.child_watch_add(pid, callback)
+    return pid
index 2b75bda..fca1d2d 100644 (file)
@@ -18,8 +18,6 @@ class OnoffProcess(OnoffDevice):
             spawned process
     @ivar starting: is either None or a GObject event source id of the
             callback sigalling the end of the activation transition.
-    @ivar watch: is either None or a GObject event source id of the
-            callback waiting for the termination of the spawned process.
     @type killed: bool
     @ivar killed: indicates whether the termination signal has been sent
             to the spawned process.
@@ -42,7 +40,6 @@ class OnoffProcess(OnoffDevice):
         self.desired_state = 0 # bit mask of just ST_ACTIVE
         self.pid = None
         self.starting = None # timeout event during start
-        self.watch = None # watch event
         self.killed = False
 
     @property
@@ -55,7 +52,7 @@ class OnoffProcess(OnoffDevice):
         assert self.pid is None
         assert self.starting is None
         logger.info("starting command %s", " ".join(self.command))
-        self.pid, self.watch = spawn_child(self.command, self.process_died)
+        self.pid = spawn_child(self.command, self.process_died)
         logger.debug("started as pid %d", self.pid)
         self.starting = GObject.timeout_add(int(1000 * self.start_wait),
                                             self.process_started)
@@ -71,8 +68,6 @@ class OnoffProcess(OnoffDevice):
 
     def process_died(self, pid, condition):
         assert self.pid == pid
-        assert self.watch is not None
-        self.watch = None
         self.pid = None
         self.killed = False
         logger.info("process %d died", pid)
@@ -91,7 +86,6 @@ class OnoffProcess(OnoffDevice):
 
     def stop_process(self):
         assert self.pid is not None
-        assert self.watch is not None
         self.cancel_start_wait()
         logger.info("killing process %d", self.pid)
         os.kill(self.pid, self.termsig)