2

以下のコードを使用して、C# とは別の「appDomain」で IronPython スクリプトを実行しています。(私はこのアプローチを使用してメモリ リークの問題を解決しました) 時間がかからない (3 分未満) スクリプトは正常に実行されます。

しかし、より長い時間 (5 分以上) かかるスクリプトが例外をスローした場合 -> System.Runtime.Remoting.RemotingException: Object '/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();
    }
  }
}
4

1 に答える 1

1

InitializeLifetimeServices をオーバーライドして null を返すのが通常のアプローチです。あなたの場合、それが可能であるとは思えません。app.config ファイルに<lifetime>要素を含めることも別の方法です。

于 2009-12-01T04:36:22.773 に答える