After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 624592 - gst-python: plugin: attempt to load plugin "python" fails with KeyError
gst-python: plugin: attempt to load plugin "python" fails with KeyError
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-python
git master
Other Linux
: Normal critical
: 0.10.20
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2010-07-17 04:17 UTC by Leo Singer
Modified: 2011-07-23 14:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch, generated with "git diff -w" (1.12 KB, patch)
2010-07-17 04:17 UTC, Leo Singer
none Details | Review
New patch, clearing error indicators after failed lookups in sys.modules (738 bytes, patch)
2010-08-27 18:17 UTC, Leo Singer
none Details | Review

Description Leo Singer 2010-07-17 04:17:17 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.
Comment 1 Leo Singer 2010-08-27 18:17:28 UTC
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?
Comment 2 Alessandro Decina 2010-08-30 09:58:58 UTC
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.
Comment 3 Dave Malcolm 2011-07-23 14:46:23 UTC
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.