File tree 1 file changed +6
-10
lines changed
1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change 1
1
2
2
# https://stackoverflow.com/a/40222538/795574
3
3
4
- # exit_register runs at the end of ipython %run or the end of the python interpreter
5
4
try :
6
5
def exit_register (fun , * args , ** kwargs ):
7
- """ Decorator that registers at post_execute. After its execution it
8
- unregisters itself for subsequent runs. """
9
6
def callback ():
10
7
fun ()
11
8
ip .events .unregister ('post_execute' , callback )
12
9
ip .events .register ('post_execute' , callback )
13
10
11
+ ip = get_ipython () # should fail if not running under ipython
14
12
15
- ip = get_ipython ()
16
13
except NameError :
17
- from atexit import register as exit_register
18
-
19
-
20
- # @exit_register
21
- # def callback():
22
- # print('I\'m done!')
14
+ # forwarding import to keep functionality even if ipython is not in use
15
+ # it's possible this isn't even needed, and we just want to execute the callback for only if
16
+ # we're running under ipython, in that case, "exit_register" -> "ipython_exit_register" and
17
+ # replace the next line with def ipython_exit_register(fun, *args, **kwargs): pass
18
+ from atexit import register as exit_register # lgtm [py/unused-import]
23
19
24
20
You can’t perform that action at this time.
0 commit comments