jeansnkicks / pyev

Automatically exported from code.google.com/p/pyev
0 stars 0 forks source link

Child watcher doesn't seem to work if started when child has already exited #13

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Here's how it looks like:

{{{
from subprocess import Popen, PIPE
from time import sleep
import pyev, signal

# loop = pyev.default_loop()
loop = pyev.default_loop(pyev.EVFLAG_SIGNALFD)

child_watcher = None
def spawn_process(watcher=None, revent=None):
    print 'check'
    child = Popen(['sleep', '0'])

    global child_watcher
    if child_watcher: child_watcher.stop()
    child_watcher = loop.child(child.pid, False, spawn_process)
    child_watcher.start()

    sleep(0.5)

sig = loop.signal(signal.SIGINT, lambda w,r: loop.stop())
sig.start()

# timer = loop.timer(0.1, 0, spawn_process)
# timer.start()
spawn_process()

loop.start()
}}}

Starting this code produces single "check" message and infinite hang in 
eventloop - child watcher doesn't seem to be triggered, even though process is 
definitely dead (as seen in strace).

Setting pyev.EVFLAG_SIGNALFD for default loop, changing reactor type or 
starting a loop before creating a watcher doesn't seem to have any effect, but 
passing '1' to sleep subprocess instead of '0' works - only already-exited 
event is not detected, it seems.

Also, I seem to have fairly similar behavior with IO watchers on pipes of 
subprocesses - if subprocess exits early, callback won't be triggered 
regardless of IO produced, while stdlib select.poll returns POLLIN event for 
the same fd properly - looks like a similar problem.

Am I doing something wrong here and this code should not work or is it really 
such an obvious problem on my system?

pyev-0.8.0, libev-4.04, python-2.7.1

Original issue reported on code.google.com by mk.fraggod@gmail.com on 8 Jun 2011 at 7:41

GoogleCodeExporter commented 8 years ago
Sorry for the very late reply.

I'm afraid I don't really see the problem here, AFAICT this is expected 
behavior (signals are compressed in libev (child watchers are handled using a 
SIGCHILD signal watcher) and your child process doesn't outlive one iteration 
of the loop).
Maybe you should try to reproduce your problem in a c example program and ask 
on the libev mailing list for someone to shed more light on this.

sorry I cannot be more helpful.

malek

Original comment by lekma...@gmail.com on 7 Jan 2012 at 3:14

GoogleCodeExporter commented 8 years ago
closing as invalid. feel free to reopen when/if you have more infos.

Original comment by lekma...@gmail.com on 10 Jan 2012 at 10:04