Threads on embedded Python

Ugo García plugin at supercable.es
Tue Jun 25 16:32:49 EDT 2002


Thanks again Chris. I've just discovered how Py_BEGIN_ALLOW_THREADS works
and it works fine for me. So at this moment I'm going to leave the main loop
in C; but the article you give me has really makes me think.... it would be
more efficient to work with threads this way and to have the main loop in
Python. I would try this when I have a little more free time... or when I
publish the engine's web with the source code, let's see if someone wants to
try this for me!! :-)

Thanks very much, Chris
--ugo

"Chris Liechti" <cliechti at gmx.net> escribió en el mensaje
news:Xns9238D6F8D5BBAcliechtigmxnet at 62.2.16.82...
> "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