Skip to content

Instantly share code, notes, and snippets.

@ajp619
Last active December 10, 2015 18:34
Show Gist options
  • Save ajp619/ddaa0f35627b066ef528 to your computer and use it in GitHub Desktop.
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.
# 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