This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author njs
Recipients flox, jdemeyer, martin.panter, neologix, njs, petri.lehtinen, pitrou, r.david.murray, rpcope1, takluyver, vilya, vstinner
Date 2018-09-19.04:00:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537329605.93.0.956365154283.issue13285@psf.upfronthosting.co.za>
In-reply-to
Content
Here's another case where this bug bites us: https://github.com/python-trio/trio/issues/673

At startup, Trio checks if SIGINT is currently being handled by Python's default SIGINT handler, and if so it substitutes its own SIGINT handler (which works just like the default SIGINT handler, except with some added magic [1]).

However, this user has a C library that installs its own handler for SIGINT. When this happens, the Python signal.getsignal() function returns stale, incorrect information (claiming that the Python signal handler is still working, even though it isn't), and this causes Trio to do the wrong thing.

Vilya's "magic cookie" approach above is the one that I was going to suggest before I saw this bug :-).

Jeroen's version seems more complicated than necessary to me, and also it doesn't seem to work for my case: I need to check what the current signal handler is and make some decision based on that result. In Jeroen's API, I can see what the Python-level signal handler is, but there's no way to find out whether that signal handler is actually in use or not. Instead, we should make signal.getsignal() do something like:

  c_handler = PyOS_getsig(signalnum);
  if c_handler == the_python_signal_handler:
      # Python is handling this signal; return the Python-level handler
      return Handlers[signalnum].func
  elif c_handler in [SIG_DFL, SIG_IGN]:
      return c_handler
  else:
      return OpaqueCookie(c_handler)

[1] https://vorpus.org/blog/control-c-handling-in-python-and-trio/
History
Date User Action Args
2018-09-19 04:00:06njssetrecipients: + njs, pitrou, vstinner, vilya, r.david.murray, flox, neologix, takluyver, petri.lehtinen, martin.panter, jdemeyer, rpcope1
2018-09-19 04:00:05njssetmessageid: <1537329605.93.0.956365154283.issue13285@psf.upfronthosting.co.za>
2018-09-19 04:00:05njslinkissue13285 messages
2018-09-19 04:00:04njscreate