Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did a bit of debugging under KVM and I found that the kernel <em>is</em> delivering signals to pid 1 when the signal handlers are installed by the standard signal module. However, when the signal is received "something" causes a clone of the process to be spawned, rather than printing the expected output.</p> <p>Here is the strace output when I send HUP to the non-working init.sig-mod:</p> <p><img src="https://i.stack.imgur.com/n0ljT.png" alt="strace output"></p> <p>Which results in a new process running (pid 23) which is a clone of init.sig-mod:</p> <p><img src="https://i.stack.imgur.com/O8Tpi.png" alt="clone of init as pid 23"></p> <p>I didn't have time to dig deeper into the cause, but this narrows things further. Probably something to do with Python's signal delivery logic (it registers a C hook which invokes your bytecode function when called). The ctypes technique bypasses this. The relevant Python source files are <a href="http://svn.python.org/view/python/tags/r271/Python/pythonrun.c?view=markup" rel="nofollow noreferrer">Python/pythonrun.c</a> and <a href="http://svn.python.org/view/python/tags/r271/Modules/signalmodule.c?view=markup" rel="nofollow noreferrer">Modules/signalmodule.c</a>, in case you want to take a closer look.</p> <p><strong>Old Info</strong> -- I'm not sure this will solve your problem, but might get you closer. I compared these different ways signal handlers are installed:</p> <ul> <li>Installing a handler via Python's signal module.</li> <li>Upstart's signal handlers.</li> <li>Using ctypes to call the <code>signal()</code> syscall directly.</li> <li>Some quick tests in C.</li> </ul> <p>Both the ctypes-invoked <code>signal()</code> system call and Upstart's <code>sigaction()</code> syscalls set the <code>SA_RESTART</code> flag when the handler is registered. Setting this flag indicates that when a signal is received while the process is executing or blocking inside certain syscalls (read, write, wait, nanosleep, etc), after the signal handler completes the syscall should be automatically restarted. The application won't be aware of this.</p> <p>When Python's signal module registers a handler, it zeros the SA_RESTART flag by calling <code>siginterrupt(signum, 1)</code>. This says to the system "when a system call is interrupted by a signal, after the signal handler completes set errno to EINTR and return from the syscall". This leaves it up to the developer to handle this and decide whether to restart the system call.</p> <p>You can set the SA_RESTART flag by registering your signal this way:</p> <pre><code>import signal signal.signal(signal.SIGHUP, handler) signal.siginterrupt(signal.SIGHUP, False) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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