Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83328d2

Browse files
committed
made InterruptTest more robust
should resolve this failure:https://github.com/pythonnet/pythonnet/pull/1392/checks?check_run_id=1944113649related to#1337
1 parentd0d7616 commit83328d2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

‎src/embed_tests/TestInterrupt.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
21
usingSystem;
2+
usingSystem.Diagnostics;
33
usingSystem.Threading;
44
usingSystem.Threading.Tasks;
55

@@ -30,34 +30,35 @@ public void Dispose()
3030
[Test]
3131
publicvoidInterruptTest()
3232
{
33-
intrunSimpleStringReturnValue=int.MinValue;
34-
ulongpythonThreadID=ulong.MinValue;
35-
Task.Factory.StartNew(()=>
33+
longpythonThreadID=0;
34+
varasyncCall=Task.Factory.StartNew(()=>
3635
{
3736
using(Py.GIL())
3837
{
39-
pythonThreadID=PythonEngine.GetPythonThreadID();
40-
runSimpleStringReturnValue=PythonEngine.RunSimpleString(@"
38+
Interlocked.Exchange(refpythonThreadID,(long)PythonEngine.GetPythonThreadID());
39+
returnPythonEngine.RunSimpleString(@"
4140
import time
4241
4342
while True:
4443
time.sleep(0.2)");
4544
}
4645
});
4746

48-
Thread.Sleep(200);
49-
50-
Assert.AreNotEqual(ulong.MinValue,pythonThreadID);
47+
vartimeout=Stopwatch.StartNew();
48+
while(Interlocked.Read(refpythonThreadID)==0)
49+
{
50+
Assert.Less(timeout.Elapsed,TimeSpan.FromSeconds(5),"thread ID was not assigned in time");
51+
}
5152

5253
using(Py.GIL())
5354
{
54-
intinterruptReturnValue=PythonEngine.Interrupt(pythonThreadID);
55+
intinterruptReturnValue=PythonEngine.Interrupt((ulong)Interlocked.Read(refpythonThreadID));
5556
Assert.AreEqual(1,interruptReturnValue);
5657
}
5758

58-
Thread.Sleep(300);
59+
Assert.IsTrue(asyncCall.Wait(TimeSpan.FromSeconds(5)),"Async thread was not interrupted in time");
5960

60-
Assert.AreEqual(-1,runSimpleStringReturnValue);
61+
Assert.AreEqual(-1,asyncCall.Result);
6162
}
6263
}
6364
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp