GNOME Bugzilla – Bug 624592
gst-python: plugin: attempt to load plugin "python" fails with KeyError
Last modified: 2011-07-23 14:46:23 UTC
Created attachment 166052 [details] [review] Proposed patch, generated with "git diff -w" Whenever I do an action that causes GStreamer to try to load the "python" plugin (e.g. nuking my registry, and running gst-inspect) I see the following error message: 0:00:00.042414258 4042 0x2221030 ERROR pyplugin gstpythonplugin.c:267:pygst_require: the pygst module is not available! KeyError: 'pygst' 0:00:00.042578175 4042 0x2221030 WARN GST_PLUGIN_LOADING gstplugin.c:557:gst_plugin_register_func: plugin "/home/lsinger/opt/gstlal/lib/gstreamer-0.10/libgstpython.so" failed to initialise The "KeyError" made me think of the calls to PySys_GetObject in plugin/gstpythonplugin.c, so I tried commenting them out, and my Python plugin (with all of my Python elements) showed up again. I don't really understand why this fixed it, but hopefully this will be a useful clue to help someone to track it down. I've attached a patch that shows what I did. Since most of the change is actually indentation of "if" statements, I used "git diff -w" to suppress white space. I am using GStreamer built from git. I pulled just after Release 0.10.30 was announced. I am on an x86-64 box running Debian Testing.
Created attachment 168918 [details] [review] New patch, clearing error indicators after failed lookups in sys.modules The KeyError occurs if you call PyMapping_GetItemString with a key that is not in the mapping. Because at this point "gst" has not yet been imported, this raises an exception. The solution was to clear the error indicator using PyErr_Clear() after each of the two failed PyMapping_GetItemString() calls. By the way, I am on Debian testing. When I run "python --version", I get "Python 2.6.6rc1+". Is it possible that in earlier versions of Python PyMapping_GetItemString did not raise an exception? Or is it possible that in earlier versions of Python PyImport_ImportModule() did not check to see if the error indicator was set?
commit 2c31e12c5eccf74415ccdc643affa5c81547d4da Author: Leo Singer <lsinger@calltech.edu> Date: Mon Aug 30 11:57:07 2010 +0200 plugin: fix spurious exceptions in pygst_require. Fixes #624592.
FWIW, Python 2.7 removed a call to PyErr_Clear in the import machinery, and this was backported to 2.6.6 This is: http://svn.python.org/view?view=revision&revision=79204 where the significant change seems to be: http://svn.python.org/view/python/branches/release26-maint/Python/import.c?r1=79204&r2=79203&pathrev=79204 apparently motivated by http://bugs.python.org/issue3137 So I believe that this gstreamer code was always setting the thread-local exception state, but in older python versions it was being cleared; but in 2.7 and 2.6.6 onwards you'll see the exception.