question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gstreamer/PyGObject breaks SIGINT handling

See original GitHub issue

GLib.MainLoop.__init__ installs a SIGINT handler which calls GLib.MainLoop.quit(), and then reraise a KeyboardInterrupt in that thread. However, the main thread will not notice that, and continues whatever it is doing, which mostly means that it will hang as it is waiting for something. What you would want is a KeyboardInterrupt in the main thread, as this is the original behavior when you press Ctrl+C.

I came up with this workaround / ugly monkey patch to just disable the SIGINT handler. However, a better fix would be in PyGObject to raise the KeyboardInterrupt in the main thread.

def monkeyfix_glib():
  """
  Fixes some stupid bugs such that SIGINT is not working.
  This is used by audioread, and indirectly by librosa for loading audio.
  https://stackoverflow.com/questions/16410852/
  """
  try:
    import gi
  except ImportError:
    return
  try:
    from gi.repository import GLib
  except ImportError:
    from gi.overrides import GLib
  # Do nothing.
  # The original behavior would install a SIGINT handler which calls GLib.MainLoop.quit(),
  # and then reraise a KeyboardInterrupt in that thread.
  # However, we want and expect to get the KeyboardInterrupt in the main thread.
  GLib.MainLoop.__init__ = lambda *args, **kwargs: None

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lazkacommented, May 19, 2018

fyi, pygobject 3.28+ will no longer install a signal handler there if one was already set before and will no longer change anything when not run in the main thread.

There is an easier fix to work around all this:

instead of GLib.MainLoop() do GLib.MainLoop.new(None, False) in audioread

0reactions
sampsyocommented, May 20, 2018

Got it; thanks again for the background about how this happened!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changelog — PyGObject - Read the Docs
Install a default SIGINT handler for functions which start an event loop ... test: revert parts of the previous test as it's broken...
Read more >
Signals - GStreamer
GObject signals can be used to notify applications of events specific to this object. Note, however, that the application needs to be aware...
Read more >
FPM: GStreamer
About GStreamer; Building an application ... GStreamer by using PyGObject (applications made in Python): ... signals defined by element:.
Read more >
Newest 'pygobject' Questions - Page 4 - Stack Overflow
If I include gschemas.compiled in my library, will this break ... python · gtk · pygobject ... Handling errors with gst-rtsp-server Python bindings....
Read more >
pygobject GNOME Commit-Digest - GNOME Blogs
In pygobject Simon Feltman added a Signal class for adding and connecting custom signals. (GNOME bug 434924); Phillip Wood contributed support for composer ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found