move __init__.py's import of importlib into __getattr__?
Nathan Jensen <[email protected]> Tue, 8 Aug 2023 17:46:34 -0500
| Newsgroups | gmane.comp.python.scientific.devel |
|---|---|
| Message-ID | <CANOQTQG=Do0_F2TZ8R94fbR1k-1K_7LXEFirZKuGGQ0B18BR2g@mail.gmail.com> |
Hi, On a project I work on we encountered a complicated issue when upgrading from scipy 1.8 to scipy 1.10, and we traced it to being introduced in scipy 1.9 with the changes to how scipy submodules are imported. The issue is described here: https://github.com/ninia/jep/issues/487 Some background: The application uses Jep which enables Java processes to run CPython inside the process. Jep supports two types of interpreters, SubInterpreters which use CPython's sub-interpreter API, and SharedInterpreters which do not. The application is using SubInterpreters because it predates Jep's introduction of SharedInterpreters by many years and there are pros and cons of each type of interpreter and it's not trivial to switch. Because most CPython extension modules are not coded or tested with sub-interpreters in mind, Jep introduced a concept called "shared modules" that shares a module across sub-interpreters and ensures it is only ever imported once per process and is never disposed of or garbage collected in that process. scipy is imported as a shared module so it will work in sub-interpreters but then the usage of importlib is messing up the subpackage import. It's complicated but explained in that issue I linked above. We found a fix for the issue is to move the import of importlib in scipy's __init__.py into the __getattr__ method. https://github.com/scipy/scipy/blob/main/scipy/__init__.py#L185 So what I'm wondering is, if I submitted a pull request that moved the import of importlib into __getattr__, either before the if name in modules statement or inside the if name in modules statement, is that a change that the scipy team would consider accepting for a future release? _______________________________________________ SciPy-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: [email protected]