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.
--- /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 = PyThreadState_GetDict(); // borrowed
if (ts_dict == NULL) {
PyErr_SetString(
}
Py_DECREF(rl);
+ cached_running_holder = (PyObject *)rl;
+
+ /* safe to assume state is not NULL as the call to PyThreadState_GetDict()
+ above already checks if state is NULL */
+ cached_running_holder_tsid = PyThreadState_Get()->id;
+
return 0;
}