Threads on embedded Python

Ugo García plugin at
Tue Jun 25 00:25:51 CEST 2002

Let see if I get something clear... I don't have any main loop in Python. I
only have some functions that 'control' certains object in my operation. To
be a little more clear, the task of the functions are for example, move an
object in the world generated by a game with a little intelligence. For
example: (a simple example)

    - Wait until main character is in correct position
    - Play a sound
    - Move an enemy from pos X1,Y1 to X2,Y2
    - Play an animation
    - ....
    - ....

So, I don't have a main loop, only function like that (and other kind of
functions) that a run as a thread to have all them running simultaneous. Is
there other way to do that without having threads? Do I have to have a main
loop in order to have the threads running? Perhaps running Python in a
separate thread could be a good idea.

"Chris Liechti" <cliechti at> escribió en el mensaje
news:Xns9237EECAA9CC5cliechtigmxnet at
> "Ugo García" <plugin at> 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
> 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>

More information about the Python-list mailing list