bugWeeChat - Bugs: bug #31091, python plugin: import gtk throws...

 
 

bug #31091: python plugin: import gtk throws error

Submitter:  None
Submitted:  Mon 20 Sep 2010 09:44:32 PM UTC
   
 
Category:  script API plugins Severity:  3 - Normal
Item Group:  other Status:  Need Info
Privacy:  Public Assigned to:  flashcode
Originator Name:  Leon Bogaert Originator Email:  * -email is unavailable-
Open/Closed:  Open Release:  * 0.3.3
IRC nick:  LBo
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 19 Nov 2014 06:20:44 PM UTC, comment #8: 

I can reproduce the this problem on my Fedora 21 based system, using

  • WeeChat 1.0.1, ncurses client
  • PyGTK version 2.24.0
  • Python 2.7.8
  • "anotify.py" script, version 1.0.1

when reloading "anotify" (as described in comment #6).

@SebastiĆ©n: Which version of lnotify have you been using?  It seems that lnotify has changed and does not use pynotify anymore, at least not since version 0.2.0.

This problem is related to the use of Python sub-interpreters, which seem to have trouble with native modules like gtk._gtk that modify the module directory as part of their initialization code:
https://docs.python.org/2/c-api/init.html#bugs-and-caveats

It seems like dynamic objects (gtk.so) are loaded only once per _process, which is why the initialization code is not re-run the second time the import is triggered (by importing pynotify, which imports gtk, which imports gtk), and thus the module directory of the new interpreter state is not populated with the "gdk" module.  Comment #6 was on the right track suspecting the "weird magic" that is involved in loading "gdk", and that there is at least _something on the WeeChat side (using sub-interpreters within a single process) that triggers this bug (gtk being unable to find the "virtual" gdk module).

This bug will also be triggered if two more more different Python scripts are are importing the "gtk" module -- only the first one will succeed.

However, if anything, it can be considered a bug in Python, or in the implementation details of PyGTK (not allowing for proper reloading), but it is definitely not a bug in WeeChat.  I am not sure if there is a workaround that does not involve chancing either Python or PyGTK.

Obada Mahdi <omahdi>
Fri 28 Mar 2014 05:55:55 AM UTC, comment #7: 

The bug was not waiting, it was closed. So I reopen it.

I just tried to install lnotify.py, remove it, and reinstall it again, I have no such error with gdk.
I'm using Debian Sid, Python 2.7.6, WeeChat 0.4.4-dev (same result with 0.4.3).
I tried on 2 machines: one with X, the other without X.
In both cases, I never see the error you have, so I'm not able to reproduce the problem.

Sebastien Helleu <flashcode>
Group administrator
Fri 28 Mar 2014 03:11:44 AM UTC, comment #6: 

I realize this bug has been sitting around for three years...but I'm pretty sure this is a bug in weechat.  It seems quite reproducible.  First, we start with python on the command line, just to demonstrate that things are working in general:


Python 2.7.5 (default, Nov 12 2013, 16:18:42)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pynotify
>>>


Now, we load the lnotify.py script in weechat, and it works just fine:


/script install lnotify.py
python: loading script "/home/username/.weechat/python/lnotify.py"
python: registered script "lnotify", version 0.1.3 (lnotify - A
libnotify script for weechat)


We remove the script:


/script remove lnotify.py
python: unloading script "lnotify"
python: script removed:
/home/username/.weechat/python/autoload/lnotify.py
python: script removed: /home/username/.weechat/python/lnotify.py


And now try to load it again:


python: loading script "/home/username/.weechat/python/lnotify.py"
python: stdout/stderr: Traceback (most recent call last):
python: stdout/stderr:   File
"/home/username/.weechat/python/lnotify.py", line 20, in <module>
python: stdout/stderr:     import weechat, string, pynotify
python: stdout/stderr:   File
"/usr/lib64/python2.7/site-packages/gtk-2.0/pynotify/__init__.py",
line 19, in <module>
python: stdout/stderr:     import gtk
python: stdout/stderr:   File
"/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 42,
in <module>
python: stdout/stderr:     import gdk
python: stdout/stderr: ImportError: No module named gdk
python: unable to parse file
"/home/username/.weechat/python/lnotify.py"


KABOOM!

This happens every time.  Fedora 19, python 2.7.5, weechat 0.4.3.

Now, the problematic "gdk" module is loaded through some sort of weird magic, so maybe weechat is doing something w/r/t dynamic library symbol lookups that is making this fragile?


Anonymous
Tue 21 Sep 2010 08:50:45 AM UTC, comment #5: 

I'm using Debian.

(for more discussion about bugs, please join #weechat on irc.freenode.net, it's faster than replying in bug)

Sebastien Helleu <flashcode>
Group administrator
Tue 21 Sep 2010 08:44:58 AM UTC, comment #4: 

OK, sorry. Then I'll try another distribution first. What distribution are you using?

Anonymous
Tue 21 Sep 2010 08:43:18 AM UTC, comment #3: 

I read your comment.
But I still think it's not a WeeChat bug, the error displayed is from python, not from WeeChat.
I made a test script with "import gtk", like you, and I have no error displayed in WeeChat.

Sebastien Helleu <flashcode>
Group administrator
Tue 21 Sep 2010 08:40:49 AM UTC, comment #2: 

I think you didn't read my comment:

When I use import gtk in a standalone script or in ipython it doesn't throw an error.

So I made a testscript with the gtk import, ran it as python testscript.py => no error

Started the python shell: ipython
import gtk<CR>: no error

A very simple script in Weechat (with the import and a weechat.register): error

Anonymous
Tue 21 Sep 2010 06:01:48 AM UTC, comment #1: 

I think it's not a WeeChat bug. WeeChat just displays error from python, so if you have this error, it's a python problem on your box.
Try to run python (to have interactive python shell), and do that:
import python

You should have same errors as WeeChat.

Sebastien Helleu <flashcode>
Group administrator
Mon 20 Sep 2010 09:44:32 PM UTC, original submission:  

When I use "import gtk" or a library that uses gtk in a python plugin, weechat throws an error:

python: stdout/stderr: Traceback (most recent call last):
python: stdout/stderr:   File "/home/leon/.weechat/python/windicate.py", line 24, in <module>
python: stdout/stderr:     import gtk
python: stdout/stderr:   File "/usr/lib/pymodules/python2.6/gtk-2.0/gtk/__init__.py", line 42, in <module>
python: stdout/stderr:     import gdk
python: stdout/stderr: ImportError: No module named gdk
python: unable to parse file "/home/leon/.weechat/python/windicate.py"

When I use import gtk in a standalone script or in ipython it doesn't throw an error.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by omahdi (Posted a comment)
  • -email is unavailable- added by flashcode (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-03-28 flashcode StatusInvalid Need Info
        Open/ClosedClosed Open
    2011-01-16 flashcode Open/ClosedOpen Closed
    2010-09-21 flashcode Item GroupNone other
        StatusNone Invalid
        Assigned toNone flashcode

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code