-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce13e56
commit 4c7e078
Showing
1 changed file
with
6 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
|
||
# https://stackoverflow.com/a/40222538/795574 | ||
|
||
# exit_register runs at the end of ipython %run or the end of the python interpreter | ||
try: | ||
def exit_register(fun, *args, **kwargs): | ||
""" Decorator that registers at post_execute. After its execution it | ||
unregisters itself for subsequent runs. """ | ||
def callback(): | ||
fun() | ||
ip.events.unregister('post_execute', callback) | ||
ip.events.register('post_execute', callback) | ||
|
||
ip = get_ipython() # should fail if not running under ipython | ||
|
||
ip = get_ipython() | ||
except NameError: | ||
from atexit import register as exit_register | ||
|
||
|
||
# @exit_register | ||
# def callback(): | ||
# print('I\'m done!') | ||
# forwarding import to keep functionality even if ipython is not in use | ||
# it's possible this isn't even needed, and we just want to execute the callback for only if | ||
# we're running under ipython, in that case, "exit_register" -> "ipython_exit_register" and | ||
# replace the next line with def ipython_exit_register(fun, *args, **kwargs): pass | ||
from atexit import register as exit_register # lgtm [py/unused-import] | ||
|
||
|