Message2525

Author cgroves
Recipients
Date 2006-07-12.18:19:58
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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

The patch 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
2008-02-20 17:18:33adminlinkissue1521374 messages
2008-02-20 17:18:33admincreate