Threads on embedded Python
Chris Liechti
cliechti at gmx.net
Tue Jun 25 15:05:21 EDT 2002
"Ugo García" <plugin at supercable.es> wrote in
news:1025028733.290520 at seux119:
> But, one question: you say that I don't have to have a main loop in
> order to have threads running using Py_BEGIN_ALLOW_THREADS, but don't
> known exactly how to use it. I explain: from the main loop in my C
> application I launch threads in python using PyRun_SimpleString. But
> these threads doesn't run unless I call Python to do something. How I
> have to use Py_BEGIN_ALLOW_THREADS in order not to call Python
> continuosly?
(im realy not sure if it works that way, but im hoping)
normaly Py_BEGIN_ALLOW_THREADS is used when python calls a C function in an
extension module. while the C function is executed, all python activities
are stopped. to reactivate python, while still beeing in the C func. you
can call that macro. this allows long running C funcs, without blocking
python. (note that you must call Py_END_ALLOW_THREADS before leaving the C
func).
what you want is somewhat the other way round... the macros mentioned above
won't work directly, but if you look what they do, they are
saving/restoring of thread state. it could possibly work if you use those
functions to release the global interpreter lock. but i haven't done such
things (i've started a native thread in an extension that called back to
python on events, but the main loop is in python)
i think its much easier to lauch a loop in python and let it call back to c
functions...
http://python.org/doc/current/api/threads.html
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list