Which functions are re-entrant in Python for signal library processing
<p>Discussing <a href="http://stackoverflow.com/questions/4601674/signal-handlers-and-logging-in-python">Signal handlers and logging in Python</a> the question which functions are re-entrant in Python came up in my mind.</p>

<p>The <a href="http://docs.python.org/library/signal.html" rel="nofollow">signal library</a> mention:</p>

<blockquote>
  <p>Although Python signal handlers are
  called asynchronously as far as the
  Python user is concerned, they can
  only occur between the atomic
  instructions of the Python
  interpreter. This means that signals
  arriving during long calculations
  implemented purely in C (such as
  regular expression matches on large
  bodies of text) may be delayed for an
  arbitrary amount of time.</p>
</blockquote>

<p>That re-entrance is not typical is pointed out by the <a href="http://docs.python.org/library/logging.html" rel="nofollow">logging library</a>:</p>

<blockquote>
  <p>If you are implementing asynchronous
  signal handlers using the signal
  module, you may not be able to use
  logging from within such handlers.
  This is because lock implementations
  in the threading module are not always
  re-entrant, and so cannot be invoked
  from such signal handlers.</p>
</blockquote>

<p>I'm a little bit confused because the signal library talks about the GIL (global interpreter lock) as ".. between the atomic instructions ..". In this case signals are postponed and executed as soon as the GIL is left/<em>unlocked</em>. A kind of signal queue.</p>

<p>That makes sense but it does not matter if the functions which are called by the postponed signal handler are re-entrant because they are not called within the <em>real</em> POSIX signal handler with the "re-entrant"-limitation:</p>

<blockquote>
  <p>Only a defined list of POSIX C
  functions are declared as re-entrant
  and can be called within a POSIX
  signal handler. IEEE Std 1003.1 lists
  118 re-entrant UNIX functions you find
  at <a href="https://www.opengroup.org/" rel="nofollow">https://www.opengroup.org/</a> (login
  required).</p>
</blockquote>
