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: importlib.__init__ checks for the wrong exception when looking for _frozen_importlib
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: Arfrever, brett.cannon, chris.jerdonek, pitrou, python-dev, skrah
Priority: normal Keywords:

Created on 2012-06-27 19:21 by brett.cannon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (12)
msg164188 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-06-27 19:21
If you look at http://hg.python.org/cpython/file/abcd29c9a791/Lib/importlib/__init__.py you will notice that the try/except block for seeing if _frozen_importlib exists catches ImportError, not KeyError like it should since it is checking sys. modules and not performing an import.
msg164526 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-07-02 18:53
New changeset 818db871d29a by Brett Cannon in branch 'default':
Issue #15210: If _frozen_importlib is not found in sys.modules by
http://hg.python.org/cpython/rev/818db871d29a
msg164589 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-03 10:04
Ping. The test fails erratically on many buildbots.
msg164625 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-07-03 20:56
Any suggestions on how to make the test work better? Otherwise I'm fine with dropping the test since the fix has been verified at least on my machine (and if it is broken the other VMs will notice quickly when they start to implement things).
msg164626 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-03 21:06
> Any suggestions on how to make the test work better?

I would suggest tracking what causes the failure. It seems to be
ordering-dependent, so the devguide is your friend:
http://docs.python.org/devguide/buildbots.html#ordering-dependent-failures
;)
msg164628 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-07-03 21:50
The tests that fail in succession are these:

./python -m test -uall -v test_importlib test_import
msg164629 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-07-03 22:13
If I comment out this, both tests run OK (I don't know if that
breaks anything else though):

diff --git a/Lib/importlib/test/test_api.py b/Lib/importlib/test/test_api.py
--- a/Lib/importlib/test/test_api.py
+++ b/Lib/importlib/test/test_api.py
@@ -172,7 +172,7 @@
                 del sys.modules[name]
             except KeyError:
                 continue
-        modules['_frozen_importlib'] = None
+        # modules['_frozen_importlib'] = None
         import importlib
         for name, module in modules.items():
             sys.modules[name] = module
msg164645 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-07-04 13:38
Thanks for the diagnosis, Stefan. Unfortunately that line is the crux of the test. =) I will see if I can steal some time to look at the failure to see if there is anything obvious going on.
msg164649 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-04 14:56
I could be way off (just passing through), but the test flakiness described here seems reminiscent of a discussion we had for issue 7559.  There the solution to order-dependent tests with importlib involved calling importlib.invalidate_caches() at the appropriate time.
msg164656 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-07-04 18:03
New changeset 906c69928049 by Brett Cannon in branch 'default':
Issue #15210: Greatly simplify the test for supporting importlib
http://hg.python.org/cpython/rev/906c69928049
msg164657 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-07-04 18:05
I realized the problem was that _frozen_importlib was getting set to None, which won't trigger an exception since the code was just directly accessing sys.modules. I switched to an ``import ... as ...`` clause and moved to using test.support.import_fresh_module() and that seemed to fix the problem.
msg164659 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-04 20:11
Thanks Brett!
History
Date User Action Args
2022-04-11 14:57:32adminsetgithub: 59415
2012-07-04 20:11:30pitrousetmessages: + msg164659
2012-07-04 18:05:13brett.cannonsetstatus: open -> closed

messages: + msg164657
2012-07-04 18:03:49python-devsetmessages: + msg164656
2012-07-04 14:56:11chris.jerdoneksetnosy: + chris.jerdonek
messages: + msg164649
2012-07-04 13:38:22brett.cannonsetmessages: + msg164645
2012-07-03 22:13:58skrahsetmessages: + msg164629
2012-07-03 21:50:10skrahsetnosy: + skrah
messages: + msg164628
2012-07-03 21:06:52pitrousetmessages: + msg164626
2012-07-03 20:56:35brett.cannonsetmessages: + msg164625
2012-07-03 10:04:52pitrousetstatus: closed -> open
nosy: + pitrou
messages: + msg164589

2012-07-02 18:53:40brett.cannonsetstatus: open -> closed
assignee: brett.cannon
resolution: fixed
stage: test needed -> resolved
2012-07-02 18:53:14python-devsetnosy: + python-dev
messages: + msg164526
2012-06-27 21:20:11Arfreversetnosy: + Arfrever
2012-06-27 19:21:09brett.cannoncreate