← 返回首页
bpo-1635741: Port _asyncio extension module to multiphase initialization(PEP 489) by shihai1991 · Pull Request #18032 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (1) All 2 file types selected Viewed files
Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show whitespace
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port _asyncio extension module to multiphase initialization (:pep:`489`).
88 changes: 46 additions & 42 deletions Modules/_asynciomodule.c
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3372,76 +3372,80 @@ static PyMethodDef asyncio_methods[] = {
{NULL, NULL}
};

static struct PyModuleDef _asynciomodule = {
PyModuleDef_HEAD_INIT, /* m_base */
"_asyncio", /* m_name */
module_doc, /* m_doc */
-1, /* m_size */
asyncio_methods, /* m_methods */
NULL, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
(freefunc)module_free /* m_free */
};


PyMODINIT_FUNC
PyInit__asyncio(void)
static int
_asyncio_exec(PyObject *module)
{
if (module_init() < 0) {
return NULL;
}
if (PyType_Ready(&FutureType) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&FutureIterType) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&TaskStepMethWrapper_Type) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&TaskWakeupMethWrapper_Type) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&TaskType) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&PyRunningLoopHolder_Type) < 0) {
return NULL;
}

PyObject *m = PyModule_Create(&_asynciomodule);
if (m == NULL) {
return NULL;
return -1;
}

Py_INCREF(&FutureType);
if (PyModule_AddObject(m, "Future", (PyObject *)&FutureType) < 0) {
if (PyModule_AddObject(module, "Future", (PyObject *)&FutureType) < 0) {
Py_DECREF(&FutureType);
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}

Py_INCREF(&TaskType);
if (PyModule_AddObject(m, "Task", (PyObject *)&TaskType) < 0) {
if (PyModule_AddObject(module, "Task", (PyObject *)&TaskType) < 0) {
Py_DECREF(&TaskType);
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}

Py_INCREF(all_tasks);
if (PyModule_AddObject(m, "_all_tasks", all_tasks) < 0) {
if (PyModule_AddObject(module, "_all_tasks", all_tasks) < 0) {
Py_DECREF(all_tasks);
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}

Py_INCREF(current_tasks);
if (PyModule_AddObject(m, "_current_tasks", current_tasks) < 0) {
if (PyModule_AddObject(module, "_current_tasks", current_tasks) < 0) {
Py_DECREF(current_tasks);
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}
return 0;
}

static PyModuleDef_Slot _asyncio_slots[] = {
{Py_mod_exec, _asyncio_exec},
{0, NULL}
};

static struct PyModuleDef _asynciomodule = {
PyModuleDef_HEAD_INIT, /* m_base */
"_asyncio", /* m_name */
module_doc, /* m_doc */
0, /* m_size */
asyncio_methods, /* m_methods */
_asyncio_slots, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
(freefunc)module_free /* m_free */
};

return m;
PyMODINIT_FUNC
PyInit__asyncio(void)
{
if (module_init() < 0) {
return NULL;
}
return PyModuleDef_Init(&_asynciomodule);
}
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.