-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-134160: Use multi-phase init in documentation examples #134296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
8d8b366
88c5f3f
a4ade5c
d6c42e2
97eae13
8ae6bae
bc78288
c3ab022
d65303c
aec6781
7dfd5ad
f7c72dd
c84638c
4e59e88
d68e3e3
f6465bd
1a65816
a83e266
2d10958
a28e67c
9e6bff5
d35a6b4
9cb3092
6e5b1c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -245,21 +245,30 @@ Python extension. For example:: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return PyLong_FromLong(numargs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static PyMethodDef EmbMethods[] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static PyMethodDef emb_module_methods[] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{"numargs", emb_numargs, METH_VARARGS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Return the number of arguments received by the process."}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{NULL, NULL, 0, NULL} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static PyModuleDef EmbModule = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PyModuleDef_HEAD_INIT, "emb", NULL, -1, EmbMethods, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
NULL, NULL, NULL, NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static PyModuleDef_Slot emb_module_slots[] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{Py_mod_gil, Py_MOD_GIL_NOT_USED}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{0, NULL} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having done trial conversions of NumPy to multi-phase, I think we should include the relevant PY_VERSION_HEX checks. Both Py_mod_multiple_interpreters and Py_mod_gil were added very recently. If we agree on adding these checks, we should add them for all relevant PyModuleDef_Slot structs. It is verbose, but aids in the copy-and-paste scenario.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternative:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this PR omit these slots entirely? IMO, they should be introduced later, after you compile your first module, along with a longer discussion about isolated state & thread safety. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree better to keep simple. @neonene perhaps remove the gil and interpreter slots from where we've added them in this PR unless they were already present? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed, but not all. I can complete. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
struct PyModuleDef embmodule = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.m_base = PyModuleDef_HEAD_INIT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.m_name = "emb", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.m_size = 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.m_methods = emb_module_methods, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.m_slots = emb_module_slots, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static PyObject* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PyInit_emb(void) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return PyModule_Create(&EmbModule); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return PyModuleDef_Init(&embmodule); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Insert the above code just above the :c:func:`main` function. Also, insert the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.