[IPython-dev] Extension loading

Thomas Kluyver takowl@gmail....
Sat Sep 29 10:42:25 CDT 2012


This grows out of a discussion on PR #2430
https://github.com/ipython/ipython/pull/2430

Some of our default extensions contain a global flag to prevent the
extension being loaded more than once. This is rather ugly, and fixes
us to the singleton model of one IPython shell per process. I'd like
to clear that up before more third parties copy the pattern.

One obvious way is for the extension manager to track what extensions
are loaded, and refuse to load an extension more than once. That has a
downside, though: you might want calling %load_ext more than once to
work. For instance, if the extension adds something to the namespace,
the user overwrites it, and then realises they didn't want to, calling
%load_ext again is an obvious course of action. We have a %reload_ext
magic function, but the user may not know about it.

So, I see three options:
1. The extension manager doesn't track what's loaded, and it remains
up to the extension to avoid loading twice if it wants to.*
2. The extension manager tracks what's loaded, and refuses to load
anything more than once. It's up to the user to call %reload_ext if
they need to reload something.
3. The extension manager tracks what's loaded, and calling %load_ext a
second time works like %reload_ext (optional: get rid of %reload_ext,
which has become redundant)

* Are there any cases where running the extension-loading code more
than once without reloading the module causes something to go wrong?

I think 3 would be my preference. Any thoughts?

Thanks,
Thomas


More information about the IPython-dev mailing list