views:

46

answers:

1

Hi all, I'm writing a python application using pygtk. I have a main thread who occasionally calls another thread that is supposed to build a string and then copy it on the clipboard before dying. My "slave" thread looks pretty much like this:

class Slave(threading.Thread):
    def run(self):
        s = build_string()
        c = gtk.Clipboard()
        c.set_text(s)

Unfortunately my app crashes one-third of the time, showing a message like this:

python: xcb_io.c:221: poll_for_event: Assertion `(((long) (event_sequence) - (long) (dpy->request)) <= 0)' failed.
cloudapp.py: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.

Any idea? Could it be a threading problem? I tried initializing the clipboard inside of the Slave.init, putting the string on a TextBuffer and then calling tb.copy_clipboard(c), I tried everything, none of them worked.

A: 

You can't interact with Gtk from threads without taking some necessary precautions. Check this PyGTK FAQ entry.

Marius Gedminas