ironpython3 icon indicating copy to clipboard operation
ironpython3 copied to clipboard

How to wait something

Open Tact21 opened this issue 3 years ago • 1 comments

I try waiting a function,but the process make an error "Cannot wait on monitors on this runtime." See the following example.

public class Seth(){
    main(){
        molding = "a = Utility.Readline_core("a")"
        var u = new Utility();
        var runtime = Python.CreateRuntime();
        runtime.IO.SetInput(new MemoryStream(), Encoding.Default);
        var eng = Python.GetEngine(runtime);
        var scope = eng.CreateScope();
        scope.SetVariable("Utility", u);
        var source = eng.CreateScriptSourceFromString(molding);
        eng.Execute(molding, scope);
    }
}

public class Utility
{
    private static async Task<string> Readline_core(object m = null)
    {
        if (m != null || m != string.Empty)
        {
            oncheng_input(m.ToString());
        }
        else
        {
            oncheng_input("何かを入力してください");
        }
        while (true)
        {
            if (import_temp != string.Empty)
            {
                Console.WriteLine(import_temp);
                break;
            }
            await Task.Delay(1000);
        }
        var result = import_temp;
        import_temp = string.Empty;
        return result;
    }
}

Here is Error

System.PlatformNotSupportedException: Cannot wait on monitors on this runtime. at System.Threading.Monitor.ObjWait(Int32 millisecondsTimeout, Object obj) at
 System.Threading.Monitor.Wait(Object obj, Int32 millisecondsTimeout) at 
System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at 
System.Threading.Tasks.Task.SpinThenBlockingWait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at 
System.Threading.Tasks.Task.InternalWaitCore(Int32 millisecondsTimeout, CancellationToken cancellationToken) at 
System.Threading.Tasks.Task.InternalWait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at 
System.Threading.Tasks.Task`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetResultCore(Boolean waitCompletionNotification) at 
System.Threading.Tasks.Task`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Result() at
Ferrum.Utility.Input(String mess) in C:\Users\takum\Git\GitHub\Iron_ide\BlazorApp1\Ide\scripts\Seth.cs:line 200 at Microsoft.Scripting.Interpreter.FuncCallInstruction`2[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at 
Microsoft.Scripting.Interpreter.LightLambda.Run4[CallSite,CodeContext,Object,Object,Object](CallSite arg0, CodeContext arg1, Object arg2, Object arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute3[CodeContext,Object,Object,Object](CallSite site, CodeContext arg0, Object arg1, Object arg2) at 
Microsoft.Scripting.Interpreter.DynamicInstruction`4[[IronPython.Runtime.CodeContext, IronPython, Version=3.4.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(InterpretedFrame frame) at 
Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at 
Microsoft.Scripting.Interpreter.LightLambda.Run2[CodeContext,FunctionCode,Object](CodeContext arg0, FunctionCode arg1) at 
IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at IronPython.Compiler.PythonScriptCode.Run(Scope scope) at 
IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope) at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope) at 
Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink) at Microsoft.Scripting.SourceUnit.Execute(Scope scope) at 
Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope) at Ferrum.Coder.Mold() in C:\Users\takum\Git\GitHub\Iron_ide\BlazorApp1\Ide\scripts\Seth.cs:line 80

What can I do to fix this problem

Tact21 avatar Dec 15 '21 06:12 Tact21

I'm not able to reproduce the issue with the sample code. Could you maybe provide more details on how to reproduce? Is this a Blazor app? It could be Blazor that prevents waiting on an async operation.

slozier avatar Dec 16 '21 01:12 slozier