|
11 | 11 | using System.Runtime.CompilerServices;
|
12 | 12 | using System.Runtime.InteropServices;
|
13 | 13 | using System.Text.RegularExpressions;
|
14 |
| -using System.Threading.Tasks; |
| 14 | +using System.Threading; |
15 | 15 |
|
16 | 16 | using IronPython;
|
17 | 17 | using IronPython.Hosting;
|
@@ -289,18 +289,34 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc
|
289 | 289 | engine.GetSysModule().SetVariable("argv", PythonList.FromArrayNoCopy(new object[] { source.Path }));
|
290 | 290 | var compiledCode = source.Compile(new IronPython.Compiler.PythonCompilerOptions() { ModuleName = "__main__" });
|
291 | 291 |
|
292 |
| - var task = Task<int>.Run(() => { |
| 292 | + int res = 0; |
| 293 | + int maxStackSize = 2 * 1024 * 1024; // 2 MiB |
| 294 | + var thread = new Thread(() => { |
293 | 295 | try {
|
294 |
| - return engine.Operations.ConvertTo<int>(compiledCode.Execute(scope) ?? 0); |
| 296 | + res = engine.Operations.ConvertTo<int>(compiledCode.Execute(scope) ?? 0); |
295 | 297 | } catch (SystemExitException ex) {
|
296 |
| - return ex.GetExitCode(out _); |
| 298 | + res = ex.GetExitCode(out object otherCode); |
| 299 | + } catch (ThreadAbortException) { |
| 300 | + #pragma warning disable SYSLIB0006 // 'Thread.ResetAbort is not supported and throws PlatformNotSupportedException.' |
| 301 | + Thread.ResetAbort(); |
| 302 | + #pragma warning restore SYSLIB0006 |
| 303 | + } |
| 304 | + }, maxStackSize) { |
| 305 | + IsBackground = true |
| 306 | + }; |
| 307 | + |
| 308 | + thread.Start(); |
| 309 | + |
| 310 | + if (!thread.Join(testcase.Options.Timeout)) { |
| 311 | + if(!ClrModule.IsNetCoreApp) { |
| 312 | + #pragma warning disable SYSLIB0006 // 'Thread.Abort is not supported and throws PlatformNotSupportedException.' |
| 313 | + thread.Abort(); |
| 314 | + #pragma warning restore SYSLIB0006 |
297 | 315 | }
|
298 |
| - }); |
299 |
| - if (!task.Wait(testcase.Options.Timeout)) { |
300 | 316 | NUnit.Framework.TestContext.Error.WriteLine($"{testcase.Name} timed out after {testcase.Options.Timeout / 1000.0} seconds.");
|
301 | 317 | return -1;
|
302 | 318 | }
|
303 |
| - return task.Result; |
| 319 | + return res; |
304 | 320 | } finally {
|
305 | 321 | Environment.CurrentDirectory = cwd;
|
306 | 322 | }
|
|
0 commit comments