logo       

Threading on win32: msg#00150

gnome.gtk+.python

Subject: Threading on win32

Hello everyone,

I've recently had reason to investigate how to do asynchronous
notification from worker-threads to a main-thread (which handles all
gtk related function calls). After searching the web and mailing-lists
for pygtk for examples on this topic I found out about the following
possibilities:

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

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.

Any alternative solutions to the original problem apart from the ones
listed above would be greatly appreciated.

//Hugo

Attachment: gtk_test_idle_threads.py
Description: Text document

_______________________________________________
pygtk mailing list pygtk@xxxxxxxxxx
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise