This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2019年02月08日 17:13 by pitrou, last changed 2022年04月11日 14:59 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| importerror-sample.tgz | ishimoto, 2020年10月23日 15:18 | |||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 15057 | merged | nanjekyejoannah, 2019年07月31日 15:51 | |
| Messages (19) | |||
|---|---|---|---|
| msg335097 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2019年02月08日 17:13 | |
PyImport_GetModule() returns whatever is in sys.modules, even if the module is still importing and therefore only partially initialized.
One possibility is to reuse the optimization already done in PyImport_ImportModuleLevelObject():
/* Optimization: only call _bootstrap._lock_unlock_module() if
__spec__._initializing is true.
NOTE: because of this, initializing must be set *before*
stuffing the new module in sys.modules.
*/
spec = _PyObject_GetAttrId(mod, &PyId___spec__);
if (_PyModuleSpec_IsInitializing(spec)) {
PyObject *value = _PyObject_CallMethodIdObjArgs(interp->importlib,
&PyId__lock_unlock_module, abs_name,
NULL);
if (value == NULL) {
Py_DECREF(spec);
goto error;
}
Py_DECREF(value);
}
Py_XDECREF(spec);
Issue originally mentioned in issue34572.
|
|||
| msg335100 - (view) | Author: Eric Snow (eric.snow) * (Python committer) | Date: 2019年02月08日 17:18 | |
Yeah, that makes sense. |
|||
| msg351847 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2019年09月11日 12:47 | |
New changeset 37c22206981f52ae35c28b39f7530f8438afbfdb by Brett Cannon (Joannah Nanjekye) in branch 'master': bpo-35943: Prevent PyImport_GetModule() from returning a partially-initialized module (GH-15057) https://github.com/python/cpython/commit/37c22206981f52ae35c28b39f7530f8438afbfdb |
|||
| msg356920 - (view) | Author: Valentyn Tymofieiev (Valentyn Tymofieiev) | Date: 2019年11月18日 22:11 | |
Do we plan to backport the change by nanjekyejoannah to 3.7 branch? |
|||
| msg356980 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2019年11月19日 17:37 | |
I've assigned this to Joannah to decide if she wants to backport this. |
|||
| msg357201 - (view) | Author: Valentyn Tymofieiev (Valentyn Tymofieiev) | Date: 2019年11月21日 19:30 | |
Thanks. Is it possible that this issue and https://bugs.python.org/issue38884 are duplicates? |
|||
| msg360056 - (view) | Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) | Date: 2020年01月15日 13:59 | |
The changes required to successfully do this backport are many and affect critical areas. I am not in a hurry to do this. If anyone else wants to take this up quickly, please do. |
|||
| msg360075 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2020年01月15日 21:27 | |
> The changes required to successfully do this backport are many and affect critical areas. I am not in a hurry to do this. If anyone else wants to take this up quickly, please do. Do you mean that there is a risk that the backport introduces a regression in another part of the code? If yes, I would suggest to not backport the change to *stable* branches. People survived with bug. Do you really *have to* backport the fix? Note: this issue is closed. If you consider to backport it, I suggest to reopen the issue. |
|||
| msg360399 - (view) | Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) | Date: 2020年01月21日 14:14 | |
> Do you mean that there is a risk that the backport introduces a regression in another part of the code? If yes, I would suggest to not backport the change to *stable* branches. My worry are the many changes that are required to ceval to make this back port work. Not that I think we can not successfully backport things. we can. |
|||
| msg362300 - (view) | Author: Geoffrey Bache (gjb1002) | Date: 2020年02月20日 07:39 | |
I have been experiencing what I thought was this issue in my embedded Python code. We have been using Python 3.7, so I thought upgrading to 3.8.1 would fix it, but it doesn't seem to have made any difference. My C++ code essentially can call PyImport_GetModule() from two threads simultaneously on the same module A. The symptoms I see are that one of them then gets a stacktrace in module B (imported by A), saying that some symbol defined near the end of B does not exist. I've also noticed that this happens far more often on deployed code (where Python modules end up in a zip file) than when run directly in development (where the modules are just normal files). I can't see any difference in the frequency between 3.7.5 and 3.8.1. Any ideas? Should I reopen this? |
|||
| msg362303 - (view) | Author: Geoffrey Bache (gjb1002) | Date: 2020年02月20日 08:00 | |
Oops, I mean we call PyImport_ImportModule and get these issues when the files are zipped. Unless that calls PyImport_GetModule internally I guess it's not related to this then. |
|||
| msg362329 - (view) | Author: Valentyn Tymofieiev (Valentyn Tymofieiev) | Date: 2020年02月20日 16:17 | |
@gjb1002: see also https://bugs.python.org/issue38884, which demonstrates that concurrent imports are not thread-safe on Python 3. |
|||
| msg362347 - (view) | Author: Geoffrey Bache (gjb1002) | Date: 2020年02月20日 20:22 | |
@Valentyn Tymofieiev - true, and thanks for the tip, though the symptoms described there are somewhat different from what I'm observing. Also, my problem seems to be dependent on zipping the Python code, which that one isn't. |
|||
| msg379441 - (view) | Author: Atsuo Ishimoto (ishimoto) * | Date: 2020年10月23日 15:18 | |
After this fix, some functions like multiprocessing.Pool cannot be used in threaded code(https://bugs.python.org/issue41567). importerror-sample.tgz contains simplified code to reproduce the same error without multiprocessing module. Is this an expected behaviour of this change? Tested with Python 3.9.0/macOS 10.15.5. |
|||
| msg383433 - (view) | Author: Big Stone (Big Stone) | Date: 2020年12月20日 16:22 | |
Is this bug causing the Dask-Jupyterlab failure ? https://github.com/dask/distributed/issues/4168 |
|||
| msg388846 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2021年03月16日 15:22 | |
Note the conjunction of this change + issue32596 produces import fragility: https://bugs.python.org/issue43515 |
|||
| msg388847 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2021年03月16日 15:27 | |
Ok, going through other open issues including on third-party projects, I think these changes should unfortunately be reverted. The regressions produced are far from trivial and most developers seem at a loss how to fix them. |
|||
| msg388849 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2021年03月16日 15:44 | |
After analysis, it may not need reversal. There is a simple logic error it seems. Will check. |
|||
| msg388857 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2021年03月16日 16:17 | |
Created a new issue + fix in issue43517. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:59:11 | admin | set | github: 80124 |
| 2021年03月16日 16:17:49 | pitrou | set | status: open -> closed resolution: fixed messages: + msg388857 stage: needs patch -> resolved |
| 2021年03月16日 15:44:10 | pitrou | set | messages: + msg388849 |
| 2021年03月16日 15:43:44 | pitrou | set | status: closed -> open stage: resolved -> needs patch resolution: fixed -> (no value) versions: + Python 3.9, Python 3.10, - Python 3.7, Python 3.8 |
| 2021年03月16日 15:27:34 | pitrou | set | messages: + msg388847 |
| 2021年03月16日 15:22:29 | pitrou | set | messages: + msg388846 |
| 2020年12月28日 22:49:32 | cebtenzzre | set | nosy:
+ cebtenzzre |
| 2020年12月20日 16:22:46 | Big Stone | set | nosy:
+ Big Stone messages: + msg383433 |
| 2020年10月23日 15:18:57 | ishimoto | set | files:
+ importerror-sample.tgz nosy: + ishimoto messages: + msg379441 |
| 2020年02月20日 20:22:19 | gjb1002 | set | messages: + msg362347 |
| 2020年02月20日 16:17:39 | Valentyn Tymofieiev | set | messages: + msg362329 |
| 2020年02月20日 08:00:19 | gjb1002 | set | messages: + msg362303 |
| 2020年02月20日 07:39:32 | gjb1002 | set | nosy:
+ gjb1002 messages: + msg362300 |
| 2020年01月21日 14:14:27 | nanjekyejoannah | set | messages: + msg360399 |
| 2020年01月15日 21:27:52 | vstinner | set | messages: + msg360075 |
| 2020年01月15日 13:59:48 | nanjekyejoannah | set | messages: + msg360056 |
| 2019年11月21日 19:30:35 | Valentyn Tymofieiev | set | messages: + msg357201 |
| 2019年11月19日 17:37:29 | brett.cannon | set | assignee: nanjekyejoannah messages: + msg356980 nosy: + nanjekyejoannah |
| 2019年11月18日 22:11:12 | Valentyn Tymofieiev | set | nosy:
+ Valentyn Tymofieiev messages: + msg356920 |
| 2019年09月11日 12:48:02 | brett.cannon | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019年09月11日 12:47:42 | brett.cannon | set | messages: + msg351847 |
| 2019年07月31日 15:51:07 | nanjekyejoannah | set | keywords:
+ patch stage: needs patch -> patch review pull_requests: + pull_request14806 |
| 2019年02月22日 17:27:35 | pitrou | set | nosy:
+ vstinner |
| 2019年02月08日 18:56:13 | p-ganssle | set | nosy:
+ p-ganssle |
| 2019年02月08日 17:19:40 | pitrou | set | nosy:
+ pablogsal |
| 2019年02月08日 17:18:15 | eric.snow | set | messages: + msg335100 |
| 2019年02月08日 17:13:37 | pitrou | create | |