Can Ironpython be used to run multiple Python Virtual Machine Instances in parallel?
Inspired from the game GunTactyx, where you write programs controlling fighting robots. Guntactyx used the Small language, that later is called Pawn.
I am looking into using Python as the scripting language.
My concerns are:
Interfacing to C# The scripts should interface into C# through simple functions, doing stuff like scanning for enemies, rotating and firing. I guess each function should be delayed, so they would take x ms to return.
Bad programs. The system should be tolerant to infinite loops or crashes. I would like each virtual machine to be given X ticks to execute at a time.
Limited memory usage Scripts should not be allowed to use unlimited开发者_Go百科 usage. I would like some sort of cap.
Probably alot of other problems
I would like to end up with something in this "pseudo" style.
robots = a list of robots
while(1)
foreach robot in robots
robot.tick()
gameworld.update()
The answer to your subject question is yes, you can run multiple interpreters in parallel. Generally each script will run in its own ScriptScope
, but you can also use isolated ScriptEngine
s if necessary.
You can inject variables/functions into a script's scope before running it using
scope.SetVariable
.Your best bet is to run the Python code on a separate thread and watch it; if it takes too long to return, interrupt the thread. (this is tricky to get right, but that's a different question)
I'm not sure that can enforced easily. It may be possible if you run the scripts in a different AppDomain or process, but that's a lot of extra work for minimal gain.
Just ask!
精彩评论