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.

classification
Title: [Patch] Working post import hook and lazy modules
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: christian.heimes, ncoghlan, pje
Priority: normal Keywords: patch

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:28adminsetgithub: 45917
2008-01-24 10:06:17christian.heimessetstatus: open -> closed
resolution: out of date
messages: + msg61624
2008-01-08 23:50:34christian.heimessetfiles: - py3k_post_import_hook_lazy.patch
2008-01-08 23:50:30christian.heimessetfiles: - py3k_post_import_hook4.patch
2008-01-08 23:50:27christian.heimessetfiles: - py3k_post_import_hook3.patch
2008-01-08 23:50:19christian.heimessetfiles: + py3k_post_import_lazy.patch
messages: + msg59574
2008-01-06 22:29:44adminsetkeywords: - py3k
versions: Python 3.0
2007-12-11 23:32:18christian.heimessetkeywords: + patch
files: + py3k_post_import_hook_lazy.patch
messages: + msg58475
title: First draft of a post import hook -> [Patch] Working post import hook and lazy modules
2007-12-10 23:17:43christian.heimessetfiles: + py3k_post_import_hook4.patch
messages: + msg58383
2007-12-10 18:26:34christian.heimessetfiles: - py3k_post_import_hook2.patch
2007-12-10 18:26:28christian.heimessetfiles: + py3k_post_import_hook3.patch
messages: + msg58357
2007-12-10 01:34:18christian.heimessetfiles: - py3k_post_import_hook.patch
2007-12-10 01:27:09christian.heimessetfiles: + py3k_post_import_hook2.patch
messages: + msg58334
2007-12-09 21:06:17pjesetmessages: + msg58329
2007-12-09 20:04:21christian.heimescreate