On Fri, Feb 25, 2005 at 05:23:00PM +0100, Hugo Hallqvist wrote: > Hello everyone, > 1. Using gobject.io_add_watch() to watch a filehandle for activity. > There are several variations on this one: > 1.1 Use a temporary file. (Doesn't work on windows.) > 1.2 Use a AF_INET socket. (Does work on windows, but many "personal > firewalls" get suspicious about it, so an alternative solution is > probably preferred.) > 1.3 Use os.pipe(). (This uses an extra thread per fd, due to glib's > gio_channel stuff, but otherwise should work fine.) > 2. Lock the gdk-lock inside worker-thread and schedule an function to > be called within main-thread using gobject.idle_add() .
Actually, all the glib stuff is thread safe so you shouldn't even need the gdk lock. To me the idle handler has been the most straightforward way to handle the thread notification. > 3. Use the gsource-module to make pygtk able to listen to a win32 > event. It can be found here: > http://www.daa.com.au/pipermail/pygtk/2004-February/006961.html > I have briefly tested this technique, but didn't get it to work > reliably. This otherwise seems like a very good solution. Using the gsource module might be overkill for what you want to do. I originally wrote it because I had an app that used EVENT signalled asynchronous sockets (which is probably the favorite way to handle asynchronous socket comm on Win32). Since waitable objects are so fundamental to Win32, I think some subset of gsource functionality should probably be in PyGTK (there was a Bugzilla bug, and I think someone mentioned they had a finished solution so I tabled it). I'll take a look into it shortly. > I've written a test-program which shows the points 2 and 1.3. Both > work fine on my linux installation (debian unstable, python 2.3.5, > pygtk 2.4.1), however the example using pipes hangs when run in > windows (windows xp, python 2.3.4, pygtk 2.4.1). > > Anyway, I've found a solution (point 2) which works reliably for me. > Maybe it would be good to document that it is not possible to use > os.pipe() with the gobject.io_add_watch() function on windows. That's odd, I thought it was possible to use os.pipe with io_add_watch. Unless I'm forgetting some detail about the MSCRT mess, it should work. The os.pipe functions returns CRT fds, and io_add_watch functions ust use the lame-o blocking CRT posix in worker threads. Using this just as a notification is probably too clumsy though. When I get some sleep and access to a Win box I'll give it a look. > > Any alternative solutions to the original problem apart from the ones > listed above would be greatly appreciated. I think that, for your application, using idle_add is ideal, no? If you need to move data a python safe queue would work along with idle handlers nicely. Good luck, -jkl _______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
