Work around potential Mono bug, that hangs the runtime when new threads start by lostmsu · Pull Request #1779 · pythonnet/pythonnet
I suspect the issue is actually with Mono GC and the relatively new mode of suspending threads, which has a few (closed) bugs against it, complaining about hangs. In many of those bugs (you can find them here) switching to the old preemptive mode works around the issue. I tried it for our tests, and it seems to solve it too.
The issue also vaguely mentioned in https://www.mono-project.com/docs/advanced/runtime/docs/coop-suspend/#thread-startfinish-still-bad
So the fix is to simply set MONO_THREADS_SUSPEND to preemptive in CI before running tests in Mono.
Fixes #1766
This workaround seems to solve the issue on my local machine as well as in CI. I did 5+ CI full matrix reruns to confirm. Before the fix a few MacOS legs would time out in every run.
Below is some history of finding this workaround.