I like your idea but we have following problems for signal.siginterrupt():
(1) I guess signal.siginterrupt also has some unexpected behaviour that we can not use that either at this moment:( When I integrated to the zombie reaper test case, handler will not be called when receive SIGCHLD.(also in the following case) (2)Also on some platform not all system calls will be restarted(https://lkml.org/lkml/2005/7/23/119), add this will not guarantee all system calls restart, may be in future some unexpected behaviour.

import threading
import signal
import time
import os
from multiprocessing import Process,Pipe

def _zombieReaper(signum, frame):
    print 'sigchild!!!'

def registerSignalHandler():
    signal.signal(signal.SIGCHLD, _zombieReaper)
#signal.siginterrupt(signal.SIGCHLD, False)<----uncommented this line and _zombieReaper will not be called.

def unregisterSignalHandler():
    signal.signal(signal.SIGCHLD, signal.SIG_DFL)

def child():
    for i in range(3):
        os.kill(os.getpid(), signal.SIGCHLD)

def main():
    servThread = threading.Thread(target = child)
    pip, pop = Pipe()

if __name__ == '__main__':
On 01/29/2013 11:29 AM, Zhou Zheng Sheng wrote:
on 01/25/2013 15:31, Mark Wu wrote:
On 01/25/2013 03:20 PM, Mark Wu wrote:
Great work!
The default action for SIGCHLD is ignore, so there's no problems reported before a signal handler is installed by zombie reaper. But I still have one problem: the python multiprocessing.manager code is running a new thread and according to the implementation of python's signal, only the main thread can receive the signal.
So how is the signal delivered to the server thread?

Is it possible to reap the zombie process in the main thread asynchronously and periodically? It could be more safe than using the signal handler.

It seem add this line

signal.siginterrupt(signal.SIGCHLD, False)

after registering the SIGCHLD handler can solve the problem and pass the unit test in Royce's attachment.

Another idea is to use signalfd. When using a signalfd, the targeted signal is blocked using sigprocmask, then another thread can read the signalfd to get the targeted signal. If the signalfd is created or set to non-blocking mode, we can select/poll on the signalfd for reading. I write code snippet to demo it at


Firstly yum install python-signalfd. Then run "python signalfdReaper.py" to test the demo code. In this way, SIGCHLD will not lead to interrupted calls since it's blocked.

I think both Python manager and our zombie reaper both should be patched. For Python manager, it should restart interrupted calls. For zombie reaper is should avoid SIGCHLD leading to interrupted calls.

vdsm-devel mailing list

Reply via email to