Note that there are some explanatory texts on larger screens.

plurals
  1. POPython processes stops responding to SIGTERM / SIGINT after being restarted
    text
    copied!<p>I'm having a weird problem with some python processes running using a watchdog process.</p> <p>The watchdog process is written in python and is the parent, and has a function called <em>start_child(name)</em> which uses <em>subprocess.Popen</em> to open the child process. The Popen object is recorded so that the watchdog can monitor the process using <strong>poll()</strong> and eventually end it with <strong>terminate()</strong> when needed. If the child dies unexpectedly, the watchdog calls <em>start_child(name)</em> again and records the new Popen object.</p> <p>There are 7 child processes, all of which are also python. If I run any of the children manually, I can send SIGTERM or SIGINT using <em>kill</em> and get the results I expect (the process ends).</p> <p>However, when run from the watchdog process, the child will only end after the <strong>FIRST</strong> signal. When the watchdog restarts the child, the new child process no longer responds to SIGTERM or SIGINT. I have no idea what is causing this.</p> <p><strong>watchdog.py</strong></p> <pre><code>class watchdog: # &lt;snip&gt; various init stuff def start(self): self.running = true kids = ['app1', 'app2', 'app3', 'app4', 'app5', 'app6', 'app7'] self.processes = {} for kid in kids: self.start_child(kid) self.thread = threading.Thread(target=self._monitor) self.thread.start() while self.running: time.sleep(10) def start_child(self, name): try: proc = subprocess.Popen(name) self.processes[name] = proc except: print "oh no" else: print "started child ok" def _monitor(self): while self.running: time.sleep(1) if self.running: for kid, proc in self.processes.iteritems(): if proc.poll() is not None: # process ended self.start_child(kid) </code></pre> <p>So what happens is <em>watchdog.start()</em> launches all 7 processes, and if I send any process SIGTERM, it ends, and the monitor thread starts it again. However, if I then send the new process SIGTERM, it ignores it.</p> <p>I should be able to keep sending kill -15 to the restarted processes over and over again. Why do they ignore it after being restarted?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload