Embedding Python. But not so easy.

Peter ptriller at soapwars.de
Mon Jan 19 15:37:46 EST 2009


Hi,

Right now I am in a project writing a Simulation engine, and we are right now 
in the process of evaluating a script engine.


The basic principle is a C++ engine simulating the environment and scriptable 
agents interacting with the environment.

But the current design has a special requirement to that scriptability and my 
current knowledge of the API of Python isolated two problems

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 ?

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();
}
......

// Python

y=21
...
..
# Here the execution is suspended und control handed back to the C++ code
suspend

y+=12


end




I hope that makes it clear. I did not see a way to implement this with the 
python interpreter. 

I am hoping to be proven wrong



Thanks in advance



Greets


Peter



More information about the Python-list mailing list