Skip to content

WIP MacOS tests hang 2 #1782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions src/embed_tests/Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void TestEval()
ps.Set("a", 1);
var result = ps.Eval<int>("a + 2");
Assert.AreEqual(3, result);
}
}
}

/// <summary>
Expand Down Expand Up @@ -286,7 +286,7 @@ public void TestImportScopeFunction()
public void TestVariables()
{
using (Py.GIL())
{
{
(ps.Variables() as dynamic)["ee"] = new PyInt(200);
var a0 = ps.Get<int>("ee");
Assert.AreEqual(200, a0);
Expand Down Expand Up @@ -338,34 +338,49 @@ public void TestThread()
" th_cnt += 1\n"
);
}
int th_cnt = 100;
const int th_cnt = 100;
int locked = 0, unlocked = 0, started = 0;
for (int i = 0; i < th_cnt; i++)
{
System.Threading.Thread th = new System.Threading.Thread(() =>
ThreadPool.QueueUserWorkItem(_ =>
// var th = new System.Threading.Thread(() =>
{
Interlocked.Increment(ref started);
using (Py.GIL())
{
Interlocked.Increment(ref locked);
//ps.GetVariable<dynamic>("update")(); //call the scope function dynamicly
_ps.update();
}
Interlocked.Increment(ref unlocked);
});
th.Start();
// th.Start();
}
//equivalent to Thread.Join, make the main thread join the GIL competition
int cnt = 0;
while (cnt != th_cnt)
int result = 0;
var wait = new Thread(() =>
{
int cnt = 0;
while (cnt != th_cnt)
{
using (Py.GIL())
{
cnt = ps.Get<int>("th_cnt");
}
Thread.Yield();
}

using (Py.GIL())
{
cnt = ps.Get<int>("th_cnt");
result = ps.Get<int>("res");
}
Thread.Yield();
}
using (Py.GIL())
});
wait.Start();
if (!wait.Join(timeout: TimeSpan.FromSeconds(30)))
{
var result = ps.Get<int>("res");
Assert.AreEqual(101 * th_cnt, result);
Assert.Fail($"started: {started} locked: {locked} unlocked: {unlocked}");
}
Assert.AreEqual(101 * th_cnt, result);
}
finally
{
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy