File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -331,8 +331,4 @@ private:
331
331
static inline std::vector<AsyncHandle> _timeoutIdMap;
332
332
};
333
333
334
- // See https://github.com/python/cpython/blob/v3.13.0rc1/Python/pystate.c#L1940-L1951
335
- // Python 3.13 removed it from the public API. Re-exporting here.
336
- extern PyObject *_PyThreadState_GetDict (PyThreadState *tstate);
337
-
338
334
#endif
Original file line number Diff line number Diff line change @@ -140,7 +140,13 @@ PyEventLoop PyEventLoop::_loopNotFound() {
140
140
/* static */
141
141
PyEventLoop PyEventLoop::_getLoopOnThread (PyThreadState *tstate) {
142
142
// Modified from Python 3.9 `get_running_loop` https://github.com/python/cpython/blob/7cb3a44/Modules/_asynciomodule.c#L241-L278
143
- #if PY_VERSION_HEX >= 0x03090000 // Python version is greater than 3.9
143
+
144
+ #if PY_VERSION_HEX >= 0x030d0000 // Python version is greater than 3.13
145
+ // The private `_PyThreadState_GetDict(tstate)` API gets removed in Python 3.13.
146
+ // However, the fix below cannot be a perfect replacement since the public `PyThreadState_GetDict()` API can only get from the current thread.
147
+ // We need to somehow get the thread dictionary on the main thread instead of the current thread.
148
+ PyObject *ts_dict = PyThreadState_GetDict ();
149
+ #elif PY_VERSION_HEX >= 0x03090000 // Python version is greater than 3.9
144
150
PyObject *ts_dict = _PyThreadState_GetDict (tstate); // borrowed reference
145
151
#else // Python 3.8
146
152
PyObject *ts_dict = tstate->dict ; // see https://github.com/python/cpython/blob/v3.8.17/Modules/_asynciomodule.c#L244-L245
You can’t perform that action at this time.
0 commit comments