ipython / ipython/ipython

autoreload kills variables

Open
#12,386 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.8k
Forks
4.5k
Avg merge
1d 2h
Merged PRs (30d)
6

Description

[As recommended](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html) I added
```
%load_ext autoreload
%autoreload 2
```
to my notebook and now, indeed, the modules are automatically reloaded.

Alas, I have
```
try: # https://docs.python.org/library/importlib.html
rala_all # reload will not reset rala_all
except NameError:
rala_all = {}
```
in my module. It did work before using [`importlib`](https://docs.python.org/library/importlib.html), but, with [`autoreload`](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html) I see `rala_all` being reset (to an empty dictionary) every time the module is reloaded.

Is there a way to avoid this? I want `rala_all` to survive (auto)reload.
(also [asked](https://stackoverflow.com/q/62204805/850781)).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.