This adds a stop the world pause to make the two functions thread-safe
when the GIL is disabled in the free-threaded build.
Additionally, the main test thread may call `sys._current_exceptions()` as
soon as `g_raised.set()` is called. The background thread may not yet reach
the `leave_g.wait()` line.
# And the next record must be for g456().
filename, lineno, funcname, sourceline = stack[i+1]
self.assertEqual(funcname, "g456")
- self.assertTrue(sourceline.startswith("if leave_g.wait("))
+ self.assertTrue((sourceline.startswith("if leave_g.wait(") or
+ sourceline.startswith("g_raised.set()")))
finally:
# Reap the spawned thread.
leave_g.set()
* Because these lists can mutate even when the GIL is held, we
* need to grab head_mutex for the duration.
*/
+ _PyEval_StopTheWorldAll(runtime);
HEAD_LOCK(runtime);
PyInterpreterState *i;
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
done:
HEAD_UNLOCK(runtime);
+ _PyEval_StartTheWorldAll(runtime);
return result;
}
* Because these lists can mutate even when the GIL is held, we
* need to grab head_mutex for the duration.
*/
+ _PyEval_StopTheWorldAll(runtime);
HEAD_LOCK(runtime);
PyInterpreterState *i;
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
done:
HEAD_UNLOCK(runtime);
+ _PyEval_StartTheWorldAll(runtime);
return result;
}