8000 gh-101758: Add a Test For Single-Phase Init Modules in Multiple Interpreters by ericsnowcurrently · Pull Request #101920 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-101758: Add a Test For Single-Phase Init Modules in Multiple Interpreters #101920

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Check attrs in m_copy.
  • Loading branch information
ericsnowcurrently committed Feb 15, 2023
commit e832631f3a937ebe373ce7455708e5036851e24f
6 changes: 6 additions & 0 deletions Lib/test/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ def clean_up():
if lookedup is not _testsinglephase:
raise Exception((_testsinglephase, lookedup))

# Attrs set in the module init func are in m_copy.
_initialized = _testsinglephase._initialized
initialized = _testsinglephase.initialized()
if _initialized != initialized:
raise Exception((_initialized, initialized))

# Attrs set after loading are not in m_copy.
if hasattr(_testsinglephase, 'spam'):
raise Exception(_testsinglephase.spam)
Expand Down
10 changes: 10 additions & 0 deletions Modules/_testsinglephase.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ init_module(PyObject *module, module_state *state)
if (PyModule_AddObjectRef(module, "str_const", state->str_const) != 0) {
return -1;
}

double d = _PyTime_AsSecondsDouble(state->initialized);
PyObject *initialized = PyFloat_FromDouble(d);
if (initialized == NULL) {
return -1;
}
if (PyModule_AddObjectRef(module, "_initialized", initialized) != 0) {
return -1;
}

return 0;
}

Expand Down
0