[英]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的启发,您在其中编写了控制战斗机器人的程序。 Guntactyx used the Small language, that later is called Pawn. Guntactyx使用了Small语言,后来称为Pawn。
I am looking into using Python as the scripting language. 我正在研究使用Python作为脚本语言。
My concerns are: 我担心的是:
Interfacing to C# The scripts should interface into C# through simple functions, doing stuff like scanning for enemies, rotating and firing. 与C#的接口脚本应通过简单的功能与C#进行接口,进行扫描敌人,旋转和发射等操作。 I guess each function should be delayed, so they would take x ms to return. 我猜每个功能都应该延迟,因此它们将花x毫秒返回。
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. 我希望每个虚拟机可以一次获得X滴答声来执行。
Limited memory usage Scripts should not be allowed to use unlimited 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. 通常,每个脚本将在其自己的ScriptScope
运行,但是如果需要,您也可以使用隔离的ScriptEngine
。
You can inject variables/functions into a script's scope before running it using scope.SetVariable
. 您可以在使用scope.SetVariable
运行脚本之前将变量/函数注入脚本的作用域。
Your best bet is to run the Python code on a separate thread and watch it; 最好的选择是在单独的线程上运行Python代码并观看它; 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. 如果您可以在其他AppDomain或进程中运行脚本,则可能会出现这种情况,但这需要大量的额外工作才能使收益最小。
Just ask! 只是问问!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.