python - Forking a child in another thread: parent doesn't receive SIGCHLD on termination -


normally, when process fork child process, receive sigchld signal if child terminates. but, if fork happens in thread other main thread of application, parent won't receive anything.

i test in python, on different gnu/linux machines. x86_64.

my question is: python behaviour, or defined behaviour of posix standard? , in both cases, why so?


here sample code re-produce behaviour.

import signal import multiprocessing import threading import time   def signal_handler(*args):     print "signal received"  def child_process():     time.sleep(100000)  def child_thread():     p = multiprocessing.process(target=child_process)     p.start()     time.sleep(100000)   signal.signal(signal.sigchld, signal_handler)  p = multiprocessing.process(target=child_process) p.start()  t = threading.thread(target=child_thread) t.start()  time.sleep(100000) print "waked" time.sleep(100000) 

then, send sigkill each child. when first child (the 1 forked in main thread) terminates, signal_handler called. when second child terminates, nothing happen.

i test same scenario os.fork instead of multiprocessing.process. same result.

it documented python behavior:

only main thread can set new signal handler, , the main thread 1 receive signals (this enforced python signal module, if underlying thread implementation supports sending signals individual threads). means signals can’t used means of inter-thread communication. use locks instead.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -