I wrote up the example code for Python logging module and discovered odd behavior. The logging messages duplicated each time I executed: %run main.py
. At first the only way to clear the duplication was to exit iPython (CTRL-D). User unutbu posted an explantion and solution. Ok. Solved.
But as a matter of development and practice using iPython, Can I reset iPython (in a way that would remove these instances of the logger handler object) without restarting iPython?
This question has been asked before, but evidently they didn't have this test code to contend with.
How to clear variables in ipython?
The simple option was uneffective:
In [29]: %reset
Once deleted, variables cannot be recovered. Proceed (y/[n])? y
In [30]: %run main2
2018-05-12 1335:00 - WARNING - 3. This is a warning!
2018-05-12 1335:00 - WARNING - 3. This is a warning!
2018-05-12 1335:00 - WARNING - 3. This is a warning!
2018-05-12 1335:00 - WARNING - 3. This is a warning!
2018-05-12 1335:00 - WARNING - 3. This is a warning!
After restart, you will only see one of these lines, and not one for each previous execution of the %run
magic.
Another suggestion didn't work as expected (maybe something changed since 2016?):
In [28]: import IPython
...: app = IPython.Application.instance()
...: app.kernel.do_shutdown(True)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-28-59afc6e6c255> in <module>()
1 import IPython
2 app = IPython.Application.instance()
----> 3 app.kernel.do_shutdown(True)
AttributeError: 'TerminalIPythonApp' object has no attribute 'kernel'
I'm running Arch with i3, and another suggestion of CTRL-. doesn't work.