I've got a script which creates a graph, but the script keeps running in the background until the window is closed. I'd like it to quit as soon as the window is created, so that Ctrl-C in the shell won't kill the window, and so that the user can leave the window open and continue working in the shell without
mian ... &
This works for Unix:
import pylab import numpy as np import multiprocessing as mp import os def display(): os.setsid() pylab.show() mu, sigma = 2, 0.5 v = np.random.normal(mu,sigma,10000) (n, bins) = np.histogram(v, bins=50, normed=True) pylab.plot(bins[:-1], n) p=mp.Process(target=display) p.start()
When you run this script (from a terminal) the pylab plot is displayed. Pressing Ctrl-C kills the main script, but the plot remains.