Skip to content

Commit

Permalink
LGTM warning / comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Apr 27, 2021
1 parent ce13e56 commit 4c7e078
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions pyphare/pyphare/core/ipython.py
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]


0 comments on commit 4c7e078

Please sign in to comment.