-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter.py
25 lines (22 loc) · 936 Bytes
/
interpreter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Interpreter utilities
# Imports
import sys
# Determine whether running in a Jupyter notebook (to some probability)
def is_notebook():
try:
# noinspection PyUnresolvedReferences
shell = get_ipython().__class__.__name__
if shell == 'ZMQInteractiveShell':
return True # Jupyter notebook or qtconsole
elif shell == 'TerminalInteractiveShell':
return False # Terminal running IPython
else:
return False # Other type
except NameError:
return False # Probably standard Python interpreter
# Determine whether there is a debugger attached (more precisely, any debugger, profiler, code coverage tool, etc that implements sys.gettrace())
# Examples of False: Run in PyCharm, run script from console, run normal code in Jupyter notebook
# Examples of True: Debug in PyCharm, interactive Python console, explicitly debug code in Jupyter notebook
def debugger_attached():
return sys.gettrace() is not None
# EOF