Re: Embedding Python. But not so easy.
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 interpreters. 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. Diez -- http://mail.python.org/mailman/listinfo/python-list
Embedding Python. But not so easy.
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 -- http://mail.python.org/mailman/listinfo/python-list