Re: Threading in a python extension?



On Sat, 2006-17-06 at 21:35 +0200, Christian Persch wrote:
> Hi,
> 
> Le samedi 17 juin 2006 à 16:45 +0100, Magnus Therning a écrit :

> > Unfortunately I got stuck on the first step. I create a threading.Thread
> > object, passing in the synchronisation function as its target argument.
> > Then I start the thread:
> > 
> >  def _menu_callback(action, window):
> >    t = threading.Thread(target=_do_sync)
> >    t.start()
> > 
> > I've added some calls to a logger (using logging.getLogger) first thing
> > both in _menu_callback and in _do_sync. The first one is hit, but the
> > second is never reached.
> > 
> > Is it possible to do a multi-threaded extension in Python at all?
> 
> It should be possible to do threading as long as you're careful to only
> ever call gtk and epiphany functions from the main thread. There's at
> least on (C++) extension that uses threading, the error viewer's link
> validations functionality.

My guess is that you can only create threads through GLib, not through
Python's own library.

This is more of a PyGTK programming issue than an Epiphany plugin
programming one. First of all, a call to "gobject.threads_init()" might
be necessary. It maybe belongs within Epiphany itself, but it might work
if you call it in your extension's initialization code. I think
gobject.threads_init() changes how Python's threading library behaves,
so it won't crash things horribly.

Anyway, were I in your shoes I'd research how to use threads within
PyGTK. But as Christian said, g_idle_add() is usually a better choice.
External libraries (such as GnomeVFS) can handle asynchronous networking
quite well (i.e., they hide the threads), if that's what you're trying
to implement.

-- 
Adam Hooper <adamh densi com>

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]