IronLanguages / ironpython3

Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime.
Apache License 2.0
2.48k stars 287 forks source link

If call Python and there is an infinite loop in Python, where can set the timeout? #1800

Open chenkaiguo opened 5 months ago

chenkaiguo commented 5 months ago

When running the following code, it will get stuck all the time. Is there any solution?

c# code:


ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();

return engine.Execute(@"import math 
def myadd(a, b):
    while True:
        a += 1
        b += 1
    return a + b 
myadd(2, 3)", scope);