开发者

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:

  1. 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.

  2. 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.

  3. Limited memory usage Scripts should not be allowed to use unlimited开发者_Go百科 usage. I would like some sort of cap.

  4. 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 ScriptEngines if necessary.

  1. You can inject variables/functions into a script's scope before running it using scope.SetVariable.

  2. 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)

  3. 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.

  4. Just ask!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜