◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
2 changes: 2 additions & 0 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
* if it is NULL. */
PyAPI_FUNC(PyThreadState *) _PyThreadState_UncheckedGet(void);

/* PyGILState */

/* Helper/diagnostic function - return 1 if the current thread
Expand Down
5 changes: 3 additions & 2 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,13 @@ get_running_loop(PyObject **loop)
rl = cached_running_holder; // borrowed
}
else {
if (ts->dict == NULL) {
goto not_found;
}

rl = _PyDict_GetItemIdWithError(
ts->dict, &PyId___asyncio_running_event_loop__); // borrowed
if (rl == NULL) {
if (PyErr_Occurred()) {
goto error;
Expand Down
27 changes: 18 additions & 9 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include "Python.h"
#include "pycore_ceval.h"
#include "pycore_initconfig.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
#include "pycore_pylifecycle.h"

/* --------------------------------------------------------------------------
CAUTION
Expand Down Expand Up @@ -979,20 +980,28 @@ PyThreadState_Swap(PyThreadState *newts)
PyThreadState_GetDict() returns NULL, an exception has *not* been raised
and the caller should assume no per-thread state is available. */

PyObject *
PyThreadState_GetDict(void)
{
PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL)
return NULL;

if (tstate->dict == NULL) {
PyObject *d;
tstate->dict = d = PyDict_New();
if (d == NULL)
PyErr_Clear();
}
return tstate->dict;
}


Expand Down
Toggle all file notes Toggle all file annotations