Skip to content

Conversation

@takluyver
Copy link
Member

As discussed on the mailing list, extensions should track whether they are loaded per-shell, not per-process. For now, this still leaves it up to extensions what they do if the same shell attempts to load them a second time.

We could easily adjust that so that the shell will only load them once. If you try %load_ext with an already loaded extension, there are several possible behaviours we could implement:

  • It tells the user "The 'foo' extension is already loaded. To reload it, use %reload_ext foo".
  • It reloads the extension, with or without saying anything. We could optionally remove %reload_ext in this case.

There could also be a flag to force loading an extension, but it's not clear how this would differ from the current %reload_ext.

Update: This now also tries to call unload_ipython_extension() before it reloads a module, so it should be possible to avoid any problems from loading things twice.

@bfroehle
Copy link
Contributor

bfroehle commented Oct 3, 2012

While this is a beneficial change in that the state is being managed per IPython shell instead of per-process, I have to wonder why we are requiring the extensions to manage the state at all.

Could all of the if 'NAME' not in ip.extension_manager.loaded checks be moved into one central place? (i.e. in the dispatch function?)

@takluyver
Copy link
Member Author

That's mostly what the PR description is about. ;-) We certainly can, I'm just not sure yet what the best behaviour to implement is.

@takluyver
Copy link
Member Author

OK, for now I've implemented it so that calling %load_ext with an already loaded extension does nothing besides printing a message pointing the user to %reload_ext.

I've also made %unload_ext give messages both for extensions that aren't loaded, and for extensions that don't define unload_ipython_extension(ip).

@takluyver
Copy link
Member Author

@bfroehle any more thoughts on this? I might merge in a few days unless anyone objects.

bfroehle added a commit that referenced this pull request Oct 31, 2012
Track which extensions are loaded
@bfroehle bfroehle merged commit ddeb9bb into ipython:master Oct 31, 2012
@bfroehle
Copy link
Contributor

Merged. 😄 Thanks for the reminder.

@takluyver
Copy link
Member Author

Thanks!

goodok pushed a commit to goodok/sympy that referenced this pull request Apr 6, 2014
Updated sympyprinting IPython extension to use the IPython
ExtensionManager tracking of loaded extensions to ensure the extension
is not re-loaded, rather than using a global variable.

This is introduced in IPython pull sympy#2462 [1]. Support for using a global
variable is maintained for older versions of IPython.

[1] ipython/ipython#2462
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants