why does my pygtk application crash when copying text on a clipboard?

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()

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.


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

Need Your Help

Force refresh cache on js/css/html changes webapp

javascript html css firefox browser-cache

I need the browser to get changes instead of the cached ones after doing any javascript, css, or HTML changes.

c++ compile error in codechef.com


I am trying to submit the solution of Adding Least Common Multiples(July contest) in codechef.com.