| msg58323 - (view) |
Author: Christian Heimes (christian.heimes) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
Date: 2008-01-24 10:06 |
| The post import hook patch is in my pep 369 branch. |
|
|