【发布时间】:2009-12-01 03:54:20
【问题描述】:
我正在使用以下代码在来自 c# 的单独“appDomain”上执行 IronPython 脚本。 (我使用这种方法来解决内存泄漏问题) 花费较少时间(少于 3 分钟)的脚本执行良好。
但是如果脚本需要更长的时间(超过 5 分钟)抛出异常说 -> System.Runtime.Remoting.RemotingException:对象'/011b230e_2f28_4caa_8bbc_92fabb63b311/vhpajnwe48ogwedf6zwikqow_4.rem'
using System;
using Microsoft.Scripting;
namespace PythonHostSamle
{
class Program
{
static void Main(string[] args)
{
AppDomain sandbox = AppDomain.CreateDomain("sandbox");
var engine = IronPython.Hosting.Python.CreateEngine(sandbox);
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\Python25\Lib");
searchPaths.Add(@"C:\RevitPythonShell");
engine.SetSearchPaths(searchPaths);
ScriptScope scope = engine.ExecuteFile("C:\Python25\Test.py")
// Script takes morethan 5mins to execute(sleep in the script)
ObjectHandle oh = scope.GetVariableHandle("GlobalVariableName")
// System throws following exception
//System.Runtime.Remoting.RemotingException:
// Object '/011b230e_2f28_4caa_8bbc_92fabb63b311/vhpajnwe48ogwedf6zwikqow_4.rem'
Console.ReadKey();
}
}
}
【问题讨论】:
-
我没有真正的解决方案,但作为快速解决方案,我相信您可以通过设置 LifetimeServices.LeaseTime 来增加 AppDomain 的远程处理超时。我相信必须在 target AppDomain 中执行(虽然尚未测试!)。最简单的方法可能是让 Python 引擎在沙箱域中为您设置属性。
标签: c# ironpython embedding