multiprocess.py 1.5 KB
Newer Older
1 2 3 4
# -*- coding: utf-8 -*-
import initExample ## Add path to library (just for examples; you do not need this)
import numpy as np
import pyqtgraph.multiprocess as mp
5
import pyqtgraph as pg
6 7 8 9 10
import time




11
print("\n=================\nStart Process")
12 13
proc = mp.Process()
import os
14 15
print("parent:", os.getpid(), "child:", proc.proc.pid)
print("started")
16 17
rnp = proc._import('numpy')
arr = rnp.array([1,2,3,4])
18 19 20 21 22
print(repr(arr))
print(str(arr))
print("return value:", repr(arr.mean(_returnType='value')))
print( "return proxy:", repr(arr.mean(_returnType='proxy')))
print( "return auto: ", repr(arr.mean(_returnType='auto')))
23
proc.join()
24
print( "process finished")
25 26 27



28
print( "\n=================\nStart ForkedProcess")
29 30 31
proc = mp.ForkedProcess()
rnp = proc._import('numpy')
arr = rnp.array([1,2,3,4])
32 33 34
print( repr(arr))
print( str(arr))
print( repr(arr.mean()))
35
proc.join()
36
print( "process finished")
37 38 39 40 41 42 43 44




import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
app = pg.QtGui.QApplication([])

45
print( "\n=================\nStart QtProcess")
46 47
import sys
if (sys.flags.interactive != 1):
48
    print( "   (not interactive; remote process will exit immediately.)")
49 50 51 52 53 54 55 56 57 58 59
proc = mp.QtProcess()
d1 = proc.transfer(np.random.normal(size=1000))
d2 = proc.transfer(np.random.normal(size=1000))
rpg = proc._import('pyqtgraph')
plt = rpg.plot(d1+d2)


## Start Qt event loop unless running in interactive mode or using pyside.
#import sys
#if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
    #QtGui.QApplication.instance().exec_()