Re: C-thread calling Python
- From: Richard Procter <richard n procter gmail com>
- To: python-hackers-list gnome org
- Subject: Re: C-thread calling Python
- Date: Fri, 20 Jan 2012 08:16:46 +1300
Hi Matthias,
I have held off replying in case someone more knowledgeable might
step in here; I have only dipped my toes into threading on
python/pygobject; below are some reflections to take with a grain of salt.
> Date: Tue, 17 Jan 2012 12:31:43 +0100
> From: Matthias Vogelgesang <matthias vogelgesang gmail com>
> Subject: Re: python-hackers-list Digest, Vol 21, Issue 2
> [snip]
> I do it rather similarly but as I am building a pure GLib app from
> GObject-based library, I don't have any Gtk dependencies and therefore
> the Gtk main loop is not helping. I will just sketch, how it is done
> now (Foo is the GObject-based library written in C):
>
> from gi.repository import Foo, GObject
>
> class MyFilter(Foo.Filter):
> def do_process(self, data):
> print data
>
> if __name__ == '__main__':
> GObject.threads_init()
> f = MyFilter()
> caller = Foo.Caller()
> caller.call(f, None)
>
> foo_caller_call() basically creates a thread that calls the
> foo_filter_process() method of the passed object and joins this
> thread. If I don't create a thread but just call foo_filter_process()
> from foo_caller_call() everything works fine and the Python code is
> executed.
If Foo.Caller.call() is purely GLib then it is presumably not creating
threads using the python API. These require care to execute safely within
the python interpreter [1]. I note though that my code-generated GTK+2
pygobject wrappers supply this in the C method proxies that call into a python
subclass of a wrapped gobject.
Are you saying that do_process() is never executed if you call it from
the C-level in a newly created non-python thread? It may be worth
while determining exactly where the call stalls to test the presumption
that the C-level code is blocking trying to acquire the GIL before executing
do_process().
Without more detail I can't be more specific. I've never done what you are doing
but, at least conceptually, I see no reason why it cannot work. I can't afford
the time to reply further I'm afraid.
warm regards,
Richard.
[1] http://docs.python.org/c-api/init.html#non-python-created-threads
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]