Issue1521362

classification
Title: second import of broken module succeeds
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: cgroves
Priority: normal Keywords:

Created on 2006-07-12.17:48:35 by cgroves, last changed 2006-07-12.18:14:12 by cgroves.

Files
File name Uploaded Description Edit Remove
badmodule.py cgroves, 2006-07-12.17:48:36
doubleImport.patch cgroves, 2006-07-12.18:14:12
Messages
msg1176 (view) Author: Charlie Groves (cgroves) Date: 2006-07-12.17:48:35
If I have a module that throws an exception on import,
the first time I try to import it I get an ImportError.
 The second time I try to import it, the import succeeds.

milo:~/dev/jython groves$ jytip
Jython 2.2a1 on java1.5.0_06 (JIT: null)
Type "copyright", "credits" or "license" for more
information.
>>> try:
...   import badmodule
... except:
...   pass
... 
>>> import badmodule
>>> print badmodule
<module 'badmodule' from
'/Users/groves/dev/jython/badmodule.py'>

milo:~/dev/jython groves$ python
Python 2.4.3 (#1, Apr  7 2006, 10:54:33) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for
more information.
>>> try:
...   import badmodule
... except:
...   pass
...    
>>> import badmodule
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/Users/groves/dev/jython/badmodule.py", line 1,
in ?
    import nonexistentmodule
ImportError: No module named nonexistentmodule
msg1177 (view) Author: Charlie Groves (cgroves) Date: 2006-07-12.18:14:12
Logged In: YES 
user_id=1174327

The attached patch fixes this problem.  It surrounds the
actual import code with a try catch, and if an exception is
thrown it removes the module from the modules list and
rethrows the exception.  I think all import code eventually
flows through here to actually run the import so I think it
fixes everything, but someone with more knowledge of the
Jython import system should probably take a look at this.
History
Date User Action Args
2006-07-12 17:48:35cgrovescreate