Debugger: Delay matplot process initialization

Reduces costs in case the feature is not requested.

Change-Id: I66da6f256baaec6ef9d40bc135942551d58e83da
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2015-01-28 17:04:42 +01:00
parent 401d66764c
commit c5c229b48f

View File

@@ -91,24 +91,33 @@ except:
if hasSubprocess and hasPlot: if hasSubprocess and hasPlot:
matplotFigure = {} matplotFigure = {}
matplotCount = 0 matplotCount = 0
matplotProc = None
devNull = None
devNull = open(os.devnull) def matplotInit():
# FIXME: That might not be the one we want. global matplotProc
pythonExecutable = sys.executable global devNull
matplotProc = subprocess.Popen(args=[pythonExecutable, "-i"],
bufsize=0, stdin=subprocess.PIPE, stdout=devNull, stderr=devNull)
matplotProc.stdin.write(b"import sys\n") if matplotProc is None:
matplotProc.stdin.write(b"sys.ps1=''\n") devNull = open(os.devnull)
matplotProc.stdin.write(b"from matplotlib import pyplot\n") # FIXME: That might not be the one we want.
matplotProc.stdin.write(b"import time\n") pythonExecutable = sys.executable
matplotProc.stdin.write(b"pyplot.ion()\n") matplotProc = subprocess.Popen(args=[pythonExecutable, "-i"],
matplotProc.stdin.flush() bufsize=0, stdin=subprocess.PIPE, stdout=devNull, stderr=devNull)
matplotProc.stdin.write(b"import sys\n")
matplotProc.stdin.write(b"sys.ps1=''\n")
matplotProc.stdin.write(b"from matplotlib import pyplot\n")
matplotProc.stdin.write(b"import time\n")
matplotProc.stdin.write(b"pyplot.ion()\n")
matplotProc.stdin.flush()
def matplotSend(iname, show, data): def matplotSend(iname, show, data):
global matplotFigure global matplotFigure
global matplotCount global matplotCount
matplotInit()
def s(line): def s(line):
matplotProc.stdin.write(line.encode("latin1")) matplotProc.stdin.write(line.encode("latin1"))
matplotProc.stdin.write(b"\n") matplotProc.stdin.write(b"\n")
@@ -136,9 +145,11 @@ if hasSubprocess and hasPlot:
matplotProc.stdin.flush() matplotProc.stdin.flush()
def matplotQuit(): def matplotQuit():
matplotProc.stdin.write(b"exit") global matplotProc
matplotProc.kill() if not matplotProc is None:
devNull.close() matplotProc.stdin.write(b"exit")
matplotProc.kill()
devNull.close()
def arrayForms(): def arrayForms():
global hasPlot global hasPlot