Issue 1576: [Patch] Working post import hook and lazy modules (original) (raw)

Created on 2007-12-09 20:04 by christian.heimes, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
py3k_post_import_lazy.patch christian.heimes,2008-01-08 23:50
Messages (8)
msg58323 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-09 20:04
I've written a rough draft for a post import hook as discussed on the python 3000 mailing list. The implementation is far from perfect. It requires more unit tests, a code review and reference count checks.
msg58329 - (view) Author: PJ Eby (pje) * (Python committer) Date: 2007-12-09 21:06
It also needs to hold the import lock during both the "register" and "notify" operations. In addition, the "notify" operation needs to be exposed for calling from Python (so that lazy module implementations can interop). Finally, it's not clear to me whether there's any way one of the import APIs can exit with the module added to sys.modules, but *without* the notify operation being called. It seems to me that those code paths were cleared up in 2.4 (i.e. failure to import causes the module to be removed from sys.modules), but it might be good to doublecheck that.
msg58334 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-10 01:27
I've moved the result = PyImport_NotifyPostImport(result); inside the protected block. It's now protected by the import lock. I've also added the lock protection to the register function. The notify method is now exposed through the imp module, too. I've checked multiple code paths. They all end up in PyImport_ImportModuleLevel(): builtins.__import__(), PyImport_Import(), PyImport_ImportModule(). Only PyImport_ImportFrozenModule() doesn't use the code path in imp_init_frozen().
msg58357 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-10 18:26
The new patch fixes some ref leaks, corner cases and adds some new unit tests. All unit tests are passing but I'm leaking lots of references in the register function.
msg58383 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-10 23:17
UPDATES: * no ref leaks * PyModule_IsLazy(mod) checks mod.__lazy_import__ attribute (we can argue about a nice name later) * Added imp.is_lazy(mod_or_name)
msg58475 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-11 23:32
Updates: * Some minor cleanups * First draft of lazy modules implemented in C. It works but it needs some cleanup and more error checking.
msg59574 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-08 23:50
The new patch applies against the latest svn revision. Several functions were renamed.
msg61624 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-24 10:06
The post import hook patch is in my pep 369 branch.
History
Date User Action Args
2022-04-11 14:56:28 admin set github: 45917
2008-01-24 10:06:17 christian.heimes set status: open -> closedresolution: out of datemessages: +
2008-01-08 23:50:34 christian.heimes set files: - py3k_post_import_hook_lazy.patch
2008-01-08 23:50:30 christian.heimes set files: - py3k_post_import_hook4.patch
2008-01-08 23:50:27 christian.heimes set files: - py3k_post_import_hook3.patch
2008-01-08 23:50:19 christian.heimes set files: + py3k_post_import_lazy.patchmessages: +
2008-01-06 22:29:44 admin set keywords: - py3kversions: Python 3.0
2007-12-11 23:32:18 christian.heimes set keywords: + patchfiles: + py3k_post_import_hook_lazy.patchmessages: + title: First draft of a post import hook -> [Patch] Working post import hook and lazy modules
2007-12-10 23:17:43 christian.heimes set files: + py3k_post_import_hook4.patchmessages: +
2007-12-10 18:26:34 christian.heimes set files: - py3k_post_import_hook2.patch
2007-12-10 18:26:28 christian.heimes set files: + py3k_post_import_hook3.patchmessages: +
2007-12-10 01:34:18 christian.heimes set files: - py3k_post_import_hook.patch
2007-12-10 01:27:09 christian.heimes set files: + py3k_post_import_hook2.patchmessages: +
2007-12-09 21:06:17 pje set messages: +
2007-12-09 20:04:21 christian.heimes create