SwapOff

Python hacking, redux. 
« Back to blog

Multi-threading and PyGTK

The "easiest" way of integrating threads with PyGTK applications seems to be by using gobject.

Initialisation before starting the GTK main loop:

import gobject
gobject.threads_init()

Schedule any rendering functions from your thread with:

gobject.idle_add(window.queue_draw)

Also useful is the timeout_add function, which schedules periodic callbacks:

gobject.timeout_add(250, window.queue_draw)

Loading mentions Retweet

Comments (6)

Jan 06, 2009
Ryan Raaum said...
This is unrelated to the content of your post, but how do you get formatted code in the post? (I'm having problems working it out - and I have to hope that you're not doing it manually in the online text editor...)
Jan 06, 2009
Alec Thomas said...
The post was originally created in GMail, which has a fixed-width font and block-indenting.

I feel your pain though, I tried to use the Posterous rich text editor to update the post later, and it's woefully lacking :(

Jan 06, 2009
Ryan Raaum said...
Ouch - a lack of textile/markdown/rst/whatever support could be showstopper for me...
Jan 07, 2009
Ryan Raaum said...
I have learned that you can get formatted code using

[code]
int i = 0;
[/code]

Jan 07, 2009
Alec Thomas said...
Hmmm...it doesn't seem to work well in the "rich" editor. Every newline inside the [code] block results in a blank line in the output. Editing in HTML seems to be the only way to make it useful.

I have to second your comment about markdown support, I really wish it were supported.

Jan 07, 2009
Ryan Raaum said...
ah - I hadn't tried the editor. It works in regular email and in emailed text files. I've been told they're planning on textile support.

Leave a comment...

 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     Connect     twitter