Embedding Python. But not so easy.

Diez B. Roggisch deets at nospam.web.de
Tue Jan 20 15:06:46 CET 2009

> 1) Threads: the simulation is going to be run in a very parallel
> environment with several CPUs and
> http://docs.python.org/c-api/init.html#thread-state-and-
> the-global-interpreter-lock there is a global lock mentioned. Does that
> mean that the python code can not benefit from this ?

Not if it is CPU-bound, no. To overcome that, you'd either need multiple
processes, or you could try & trick the python interpreter by using renamed
DLLs, which means that  you can start several interpreters in one process.

*BUT* that's a nasty hack & you can't share objects between the

> 2) The script has to hand back control to the C++ framework without
> increasing the C execution stack. and be able to resume the execution at a
> later point.
> I try some pseudo code here to explain
> // C++:
> ctx = new ExecutionContext();
> ctx->run();
> while(ctx->stillRunning()) {
> otherStuff();
> ctx->resume();
> }

Stackless python might be of help here, google it.


More information about the Python-list mailing list