The running loop holder cache variable was always set to NULL when
calling set_running_loop.
Now set_running_loop saves the newly created running loop holder in the
cache variable for faster access in get_running_loop.
Automerge-Triggered-By: @1st1
(cherry picked from commit
529f42645d38b6b0075f256814dfb3d220ac7d92)
Co-authored-by: Tony Solomonik <tony.solomonik@gmail.com>
--- /dev/null
+Always cache the running loop holder when running
+``asyncio.set_running_loop``.
static int
set_running_loop(PyObject *loop)
{
- cached_running_holder = NULL;
- cached_running_holder_tsid = 0;
+ PyObject *ts_dict = NULL;
+
+ PyThreadState *tstate = PyThreadState_Get();
+ if (tstate != NULL) {
+ ts_dict = _PyThreadState_GetDict(tstate); // borrowed
+ }
- PyObject *ts_dict = PyThreadState_GetDict(); // borrowed
if (ts_dict == NULL) {
PyErr_SetString(
PyExc_RuntimeError, "thread-local storage is not available");
}
Py_DECREF(rl);
+ cached_running_holder = (PyObject *)rl;
+ cached_running_holder_tsid = PyThreadState_GetID(tstate);
+
return 0;
}