Last active
December 10, 2015 18:34
-
-
Save ajp619/ddaa0f35627b066ef528 to your computer and use it in GitHub Desktop.
A silly utility to launch a qtconsole in an IPython Notebook if one doesn't already exist. Just put this in a cell.
This file contains hidden or 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
# silly utility to launch a qtconsole if one doesn't exist | |
consoleFlag = True | |
consoleFlag = False # Turn on/off by commenting/uncommenting this line | |
import psutil | |
def returnPyIDs(): | |
pyids = set() | |
for pid in psutil.pids(): | |
try: | |
if "python" in psutil.Process(pid).name(): | |
pyids.add(pid) | |
except: | |
pass | |
return pyids | |
def launchConsole(): | |
before_pyids = returnPyIDs() | |
%qtconsole | |
after_pyids = returnPyIDs() | |
newid = after_pyids.difference(before_pyids) | |
assert len(newid) == 1 | |
return list(newid)[0] | |
try: | |
print qtid | |
except NameError: | |
if consoleFlag: | |
qtid = launchConsole() | |
print qtid | |
if consoleFlag and (qtid not in returnPyIDs()): | |
qtid = launchConsole() | |
print qtid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment