Skip to content

Commit 4c7e078

Browse files
committed
LGTM warning / comments
1 parent ce13e56 commit 4c7e078

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

pyphare/pyphare/core/ipython.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11

22
# https://stackoverflow.com/a/40222538/795574
33

4-
# exit_register runs at the end of ipython %run or the end of the python interpreter
54
try:
65
def exit_register(fun, *args, **kwargs):
7-
""" Decorator that registers at post_execute. After its execution it
8-
unregisters itself for subsequent runs. """
96
def callback():
107
fun()
118
ip.events.unregister('post_execute', callback)
129
ip.events.register('post_execute', callback)
1310

11+
ip = get_ipython() # should fail if not running under ipython
1412

15-
ip = get_ipython()
1613
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]
2319

2420

0 commit comments

Comments
 (0)