[pygtk] Problem with pygtk + threading.Thread.

Germán Diago germandiago at gmail.com
Tue Oct 6 00:25:28 WST 2009


Hello. I'm trying to integrate a program with an SDL window with
the SDL_WINDOWID hack.
I have successfully integrated the window in a socket.

The problem now is that I need access to the SDL window through
my GUI.

I wanted to create my SDL thread in another thread, but the way I
did it, it blocks.

So I used multiprocessing, which runs perfectly well.
The problem now is that if I use multiprocessing, passing key events
to the other process is a mess compared to doing the same thing in
threads.
But if I use threads, I don't know why, but the thread blocks (apparently)
the other thread and the GUI program does not start.

Some code here:

#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk
import os
import sys
import threading

gtk.gdk.threads_init()


class MyGameWindow(object):
      def run(self):
           ...


class MyGUIWindow(gtk.Builder):
      ...
      def run(self, mygamewindow):
        self._socket.set_size_request(ventanafollow.getAncho(),
ventanafollow.getAlto())
        self.window.show_all()
        self._plug = mygamewindow
        os.putenv("SDL_WINDOWID", str(self._socket.get_id()))


        self.proc = threading.Thread(target = self._plug.ejecutarJuego)
        self.proc.start()

        #It DOESN'T arrive here with threads, but it does with processes
        print "I arrive here and put the loop for the game to run"

        self._socket.connect("key-press-event", self.onKeyPressSocket)
        self._socket.connect("key-release-event", self.onKeyReleaseSocket)



if __name__ == '__main__':
    v = MyGUIWindow()
    w = MyGameWindow(sys.argv)
    v.run(w)
    gtk.main()

The part where it says "I arrive here and put..." is reached if I use
multiprocessing, but not if I don't use it.
I would like to use threading.Thread instead, but it blocks. Idle_add
does not work either, it freezes the
GUI part of the program. Thanks for your help.


More information about the pygtk mailing list