Threads on embedded Python

Chris Liechti cliechti at gmx.net
Mon Jun 24 17:25:51 EDT 2002


"Ugo García" <plugin at supercable.es> wrote in
news:1024952585.111238 at seux119: 

> Hi all. I have an applicattion who uses Python to control some
> processes. I've made a little script library to work with threads and
> each proccess is a Python thread. The main application make calls to
> Python in order to create these proccesses. The problem is that the
> proccess doesn't run unless I call Python to do something. Now in the
> main loop I have a line like this: 
>     PyRun_SimpleString("dummy=1");
> 
> This make Python the threads to run. The problem is that this is a
> little slow 'cause if I call Python from tha main application too many
> times the proccesses run well but not the main application, and if a
> make a big pause between calls the proccesses doesn't work at a good
> speed. Is posible to have some threads running in an embedded Python
> without making callings to it continuosly? It would be a better idea
> to have another thread who's only task is to call Python (a line that
> the one written before) in order to have the Python proccesses
> running? 

why not run python in a separate thread (created by your app) and doing the 
loop in python, like PyRun_SimpleString("while 1: mainloop()") or so?
you do have a main loop in python, don't you? otherwise you wouldn't need 
python threads, right? :-) 

you could possibly also release the GIL, but don't forget to grab it again 
when accessing the python interpreter. i'm not sure about this one, so i 
would try the above.

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list