classification
Title: Replace __import__ w/ importlib.__import__
Type: behavior Stage: needs patch
Components: Interpreter Core Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: Trundle, benjamin.peterson, brett.cannon, eric.araujo, eric.snow, haypo
Priority: normal Keywords: patch

Created on 2008-03-18 02:40 by brett.cannon, last changed 2012-02-08 00:10 by haypo.

Files
File name Uploaded Description Edit
f0b459af26fb.diff brett.cannon, 2012-02-04 16:14 review
bench_startup.py haypo, 2012-02-08 00:10
Repositories containing patches
http://hg.python.org/sandbox/bcannon#bootstrap_importlib
Messages (9)
msg63851 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-03-18 02:40
Python/import.c should be replaced by the implementation under
development contained in the py3k-importlib branch.
msg139233 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-06-27 00:46
OK, so first step is to simply replace __import__ w/ importlib.__import__ using builtins.__import__ in order to make sure that all tests pass as expected. Can probably do this by doing the switch in Py_Initialize() somewhere.

Next step after that will be seeing if _io can be used by importlib w/ the import of os postponed until after importlib is bootstrapped.
msg147625 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-11-14 18:01
Just some notes on the branch:

The FAILING file contains tests known to fail. There is a comment explaining the failure and possible fixes. If something makes it here and stays for a while it probably means upstream changes are needed (eg. test_pydoc needs ImportError to grow an attribute as to what import failed).

Python/pythonrun.c contains XXX markers of what is left to be done (although currently the zipimport comment is out-of-date and there needs to be one for exposing some APIs created in importlib.__init__). If you are looking for something to do, just search for XXX and try to tackle one of the comments.
msg149518 - (view) Author: Eric Snow (eric.snow) * Date: 2011-12-15 08:24
AFAICT, #1559549 is the ImportError attribute ticket.
msg152631 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-02-04 16:13
OK, I'm down to a single bug to be solved to call this work a "success" (there are other test failures, but they are not overtly difficult to solve).

At this point the bootstrapping is failing in the face of sub-interpreters. Specifically, when I try to load the frozen importlib code in Py_NewInterpreter() it leads to an assertion failure in the GC code when handling references in a GC generation. I have zero experience with sub-interpreters and my GC experience is rusty, so if anyone can have a look at the code I would appreciate it to see if they can figure out why loading a frozen module (while in marshal) is leading to a GC assertion error.
msg152785 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-02-06 21:53
Thanks to Benjamin, the test_capi assert failure is fixed. At this point the only failures are listed in the FAILING file and are (probably) minor.
msg152788 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2012-02-06 22:06
Is there a benchmark for import? How slow is importlib? :)
msg152814 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-02-07 18:28
On Mon, Feb 6, 2012 at 17:06, STINNER Victor <report@bugs.python.org> wrote:

>
> STINNER Victor <victor.stinner@haypocalc.com> added the comment:
>
> Is there a benchmark for import? How slow is importlib? :)
>

importlib.test.benchmark
msg152822 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2012-02-08 00:10
bench_startup.py: short script to compute the best startup time (I wrote the original script for the hash collision issue, #13703). Result on my PC:
 - original: 22.2 ms
 - importlib: 27.9 ms

So importlib adds an overhead of 25.7% in startup time.
History
Date User Action Args
2012-02-08 00:10:51hayposetfiles: + bench_startup.py

messages: + msg152822
2012-02-07 18:28:37brett.cannonsetmessages: + msg152814
2012-02-07 00:51:42brett.cannonlinkissue13959 dependencies
2012-02-06 22:06:40hayposetnosy: + haypo
messages: + msg152788
2012-02-06 21:53:33brett.cannonsetmessages: + msg152785
2012-02-04 16:14:33brett.cannonsetfiles: + f0b459af26fb.diff
keywords: + patch
2012-02-04 16:13:31brett.cannonsetmessages: + msg152631
2011-12-15 08:24:59eric.snowsetmessages: + msg149518
2011-11-24 15:18:32eric.araujosetnosy: + eric.araujo
2011-11-14 18:01:53brett.cannonsetmessages: + msg147625
2011-07-09 20:55:47eric.snowsetnosy: + eric.snow
2011-06-27 00:47:02Trundlesetnosy: + Trundle
2011-06-27 00:46:18brett.cannonsetmessages: + msg139233
2011-06-27 00:36:10brett.cannonlinkissue667770 dependencies
2011-06-27 00:30:41brett.cannonsettitle: Replace import.c with a pure Python implementation -> Replace __import__ w/ importlib.__import__
2011-06-27 00:29:53brett.cannonsethgrepos: + hgrepo34
2010-08-03 23:40:27brett.cannonsetstage: needs patch
versions: + Python 3.3, - Python 3.2
2010-08-02 08:54:14eric.araujosetversions: + Python 3.2, - Python 3.1
2008-07-12 20:20:35benjamin.petersonsetnosy: + benjamin.peterson
2008-07-12 19:50:12brett.cannonsetpriority: high -> normal
2008-07-12 19:50:02brett.cannonsetpriority: critical -> high
2008-07-12 19:49:44brett.cannonsetversions: + Python 3.1, - Python 3.0
2008-03-18 02:40:12brett.cannoncreate