ThrottledDevice: speed up quick reactivation
[~helmut/onoff.git] / onoff / process.py
index d888842..2b75bda 100644 (file)
@@ -10,7 +10,31 @@ from .gobject import spawn_child
 logger = logging.getLogger("onoff.process")
 
 class OnoffProcess(OnoffDevice):
 logger = logging.getLogger("onoff.process")
 
 class OnoffProcess(OnoffDevice):
+    """A device that in activated by starting a process and deactivated by
+    killing the process.
+
+    @type pid: int or None
+    @ivar pid: is either None if there is no process or the pid of the
+            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.
+    """
     def __init__(self, command, start_wait=0, termsig=signal.SIGTERM):
     def __init__(self, command, start_wait=0, termsig=signal.SIGTERM):
+        """
+        @type command: [str]
+        @param command: an argument vector to be executed. The first element
+                is used as executable and looked up in $PATH.
+        @param start_wait: duration of the transition period from inactive to
+                active in seconds.
+        @param termsig: termination signal to be sent to the process to
+                deactivate it. The process must exit in response to this
+                signal.
+        """
         OnoffDevice.__init__(self)
         self.command = command
         self.start_wait = start_wait
         OnoffDevice.__init__(self)
         self.command = command
         self.start_wait = start_wait
@@ -33,7 +57,7 @@ class OnoffProcess(OnoffDevice):
         logger.info("starting command %s", " ".join(self.command))
         self.pid, self.watch = spawn_child(self.command, self.process_died)
         logger.debug("started as pid %d", self.pid)
         logger.info("starting command %s", " ".join(self.command))
         self.pid, self.watch = spawn_child(self.command, self.process_died)
         logger.debug("started as pid %d", self.pid)
-        self.starting = GObject.timeout_add(1000 * self.start_wait,
+        self.starting = GObject.timeout_add(int(1000 * self.start_wait),
                                             self.process_started)
         self.changestate(self.state)
 
                                             self.process_started)
         self.changestate(self.state)