[Twisted-Python] spawnProcess - reapProcess not retrying on failures

Adi Roiban adi at roiban.ro
Tue Sep 2 03:08:49 MDT 2014


Hi,

While using spawnProcess on Linux I found out that when an invalid
executable is called there is a corner case in which a zombie process
is left until main process exists and can not be closed.

I wrote a test for this but I was not able to reproduce this error in
isolation, event if I run the test for 10000 times. reapProcess will
always succeed from the first call.

For the production code I can always reproduce the problem.

Inspecting the execution thread I found out that all pipes are closed
but spawned process is not closed yet. Due to this
Process.maybeCallProcessEnded() will call self.reapProcess().

In my case,  os.waitpid(pid, os.WNOHANG) return 0, and
self.reapProcess() will just ignore this case.

Process handlers is still registered in reapProcessHandlers but
reapAllProcesses is no longer called.

If a add a reactor.callLater(self.reapProcess) the next call to
os.waitpid will succeed and the forked process is closed.

------------

What am I doing wrong? Why reapAllProcesses is no longer called, even
if reapProcessHandlers is not empty?

My process protocol code is here
https://gist.github.com/adiroiban/bac493f00ce5e94738ce but from what I
see, this should happen for any protocol.

Many thanks,

-- 
Adi Roiban



More information about the Twisted-Python mailing list