Using pygtk with gevent

224 views
Skip to first unread message

Arnau Sanchez

unread,
Mar 14, 2010, 9:45:38 AM3/14/10
to gevent: coroutine-based Python network library
Hi!

A recent thread brought up the question 'what do you use gevent for?':

http://groups.google.com/group/gevent/browse_thread/thread/4de9703e5dca8271

I' discovered gevent after some exploration (the usual way: asyncore,
twisted, concurrence, eventlet, ...) and I like it a lot. Now I intend
to use it to build a pygtk applicattion (target: Linux/Windows), but I
found no references.

Taking the "concurrent_download.py" example as an starting point, I
made this minimum demo code:

http://zaudera/public/gtkdown.py

It works, but I have some questions:

- Has anyone used gevent with pygtk?
- Is this the correct way of joining gevent jobs when you have another
events loop?
- Why a control+c does not quit the script as usual (after all jobs
have finished)? I have to control+z and kill the process manually.
Obviously, the app will do a clean "gtk.main_quit()", and this works,
but I am afraid this might be denoting some kind of issue with my
code.

thanks,

Arnau Sanchez

unread,
Mar 14, 2010, 1:32:40 PM3/14/10
to gevent: coroutine-based Python network library
On 14 mar, 14:45, Arnau Sanchez <tokl...@gmail.com> wrote:

> http://zaudera/public/gtkdown.py

Sorry guys, that's obviously wrong, try please:

http://109.74.199.145/public/gtkdown.py

(Thanks for pointing it out, Denis)

Denis Bilenko

unread,
Mar 14, 2010, 3:03:53 PM3/14/10
to gev...@googlegroups.com
Hi Arnau,

On Sun, Mar 14, 2010 at 7:45 PM, Arnau Sanchez <tok...@gmail.com> wrote:
> - Why a control+c does not quit the script as usual (after all jobs
> have finished)? I have to control+z and kill the process manually.
> Obviously, the app will do a clean "gtk.main_quit()", and this works,
> but I am afraid this might be denoting some kind of issue with my
> code.

I've fixed it to make ctrl-c work (in the attachment). There's also
a way to exit the script after all jobs have finished, which is to spawn a new
job that will wait for the jobs and then call gtk.main_quit().

Let me know if there are other issues.

Cheers,
Denis.

gtk_gevent.py

arnau

unread,
Mar 14, 2010, 4:25:21 PM3/14/10
to gev...@googlegroups.com
Hi Denis,

On 14/03/10 20:03, Denis Bilenko wrote:

> I've fixed it to make ctrl-c work (in the attachment). There's also
> a way to exit the script after all jobs have finished, which is to spawn a new
> job that will wait for the jobs and then call gtk.main_quit().

Thanks, now it works perfect! I've added a gtk.Window with a button to test the
responsiveness and it runs smoothly.

Your code also gives me some hints about how to do it with eventlet, I am
testing both (eventlet has the advantage -when distributing- of being pure python).

thanks!
arnau

Reply all
Reply to author
Forward
0 new messages