Issue 15210: importlib.init checks for the wrong exception when looking for _frozen_importlib (original) (raw)

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:32 admin set github: 59415
2012-07-04 20:11:30 pitrou set messages: +
2012-07-04 18:05:13 brett.cannon set status: open -> closedmessages: +
2012-07-04 18:03:49 python-dev set messages: +
2012-07-04 14:56:11 chris.jerdonek set nosy: + chris.jerdonekmessages: +
2012-07-04 13:38:22 brett.cannon set messages: +
2012-07-03 22:13:58 skrah set messages: +
2012-07-03 21:50:10 skrah set nosy: + skrahmessages: +
2012-07-03 21:06:52 pitrou set messages: +
2012-07-03 20:56:35 brett.cannon set messages: +
2012-07-03 10:04:52 pitrou set status: closed -> opennosy: + pitroumessages: +
2012-07-02 18:53:40 brett.cannon set status: open -> closedassignee: brett.cannonresolution: fixedstage: test needed -> resolved
2012-07-02 18:53:14 python-dev set nosy: + python-devmessages: +
2012-06-27 21:20:11 Arfrever set nosy: + Arfrever
2012-06-27 19:21:09 brett.cannon create