本文整理汇总了Python中multiprocessing.Pipe.recv方法的典型用法代码示例。如果您正苦于以下问题:Python Pipe.recv方法的具体用法?Python Pipe.recv怎么用?Python Pipe.recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Pipe
的用法示例。
在下文中一共展示了Pipe.recv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fork
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def test_fork(self):
"""Test using a connection before and after a fork.
"""
if sys.platform == "win32":
raise SkipTest()
try:
from multiprocessing import Process, Pipe
except ImportError:
raise SkipTest()
db = Connection(self.host, self.port).pymongo_test
# Failure occurs if the connection is used before the fork
db.test.find_one()
db.connection.end_request()
def loop(pipe):
while True:
try:
db.test.insert({"a": "b"}, safe=True)
for _ in db.test.find():
pass
except:
pipe.send(True)
os._exit(1)
cp1, cc1 = Pipe()
cp2, cc2 = Pipe()
p1 = Process(target=loop, args=(cc1,))
p2 = Process(target=loop, args=(cc2,))
p1.start()
p2.start()
p1.join(1)
p2.join(1)
p1.terminate()
p2.terminate()
p1.join()
p2.join()
cc1.close()
cc2.close()
# recv will only have data if the subprocess failed
try:
cp1.recv()
self.fail()
except EOFError:
pass
try:
cp2.recv()
self.fail()
except EOFError:
pass
示例2: QuickSortMPListArray
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def QuickSortMPListArray(A,conn,NumProcs):
print str(len(A))+' starting mplarray'
if len(A)<=1 :
conn.send(A)
conn.close()
elif int(NumProcs)<1:
print 'proc limit reached, smp qs'
conn.send(QuickSortListArray(A))
conn.close()
else:
pvalue=A[0]
lesser=[x for x in A if int(x[0]) < int(pvalue[0])]
greater=[x for x in A if int(x[0]) > int(pvalue[0])]
pv=[x for x in A if int(x[0]) == int(pvalue[0])]
Procs=int(NumProcs)-1
pConnLeft,cConnLeft=Pipe()
leftProc=Process(target=QuickSortMPListArray,args=(lesser,cConnLeft,Procs))
pConnRight,cConnRight=Pipe()
rightProc=Process(target=QuickSortMPListArray,args=(greater,cConnRight,Procs))
leftProc.start()
rightProc.start()
print 'mplarray send'
conn.send(pConnRight.recv()+pv+pConnLeft.recv())
# conn.send(pConnLeft.recv()+[PivotValue]+pConnRight.recv())
conn.close()
leftProc.join()
rightProc.join()
return
示例3: QuickSortMP
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def QuickSortMP(A,conn,NumProcs):
if len(A)<=1 :
conn.send(A)
conn.close()
elif int(NumProcs)<1:
conn.send(QuickSort(A))
conn.close()
else:
PivotIndex=random.randint(0,len(A)-1)
PivotValue=A.pop(PivotIndex)
pv=[]
pv.append(int(PivotValue))
lesser=[int(x) for x in A if x < PivotValue]
greater=[int(x) for x in A if x >= PivotValue]
Procs=int(NumProcs)-1
pConnLeft,cConnLeft=Pipe()
leftProc=Process(target=QuickSortMP,args=(lesser,cConnLeft,Procs))
pConnRight,cConnRight=Pipe()
rightProc=Process(target=QuickSortMP,args=(greater,cConnRight,Procs))
leftProc.start()
rightProc.start()
leftStr=pConnLeft.recv()
rightStr=pConnRight.recv()
conn.send(leftStr+pv+rightStr)
# conn.send(pConnLeft.recv()+[PivotValue]+pConnRight.recv())
conn.close()
leftProc.join()
rightProc.join()
return
示例4: tempControlProcTest
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def tempControlProcTest(mode, cycle_time, duty_cycle, set_point, k_param, i_param, d_param, conn):
p = current_process()
print 'Starting:', p.name, p.pid
parent_conn_temp, child_conn_temp = Pipe()
ptemp = Process(name = "getrandProc", target=getrandProc, args=(child_conn_temp,))
#ptemp.daemon = True
ptemp.start()
parent_conn_heat, child_conn_heat = Pipe()
pheat = Process(name = "heatProctest", target=heatProctest, args=(cycle_time, duty_cycle, child_conn_heat))
#pheat.daemon = True
pheat.start()
while (True):
if parent_conn_temp.poll():
randnum = parent_conn_temp.recv() #non blocking receive
conn.send([randnum, mode, cycle_time, duty_cycle, set_point, k_param, i_param, d_param])
if parent_conn_heat.poll():
cycle_time, duty_cycle = parent_conn_heat.recv()
#duty_cycle = on_time/offtime*100.0
#cycle_time = on_time + off_time
if conn.poll():
mode, cycle_time, duty_cycle, set_point, k_param, i_param, d_param = conn.recv()
#conn.send([mode, cycle_time, duty_cycle])
#if mode == "manual":
parent_conn_heat.send([cycle_time, duty_cycle])
示例5: startWith2Threads
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def startWith2Threads(trainData, labels, testData):
print("startWith4Threads started")
parent_conn1, child_conn1 = Pipe()
parent_conn2, child_conn2 = Pipe()
t1 = threading.Thread(target=RunAllFeatures, args = (trainData, labels, testData, child_conn1, 0, 20, ))
t2 = threading.Thread(target=RunAllFeatures, args = (trainData, labels, testData, child_conn2, 20, 39, ))
t1.start()
t2.start()
rr1 = parent_conn1.recv()
rr2 = parent_conn2.recv()
t1.join();
t2.join();
print("all tasks done")
rr1 = np.row_stack((rr1, rr2))
print("result combined")
res = np.transpose(rr1)
pp = Normalization(res)
print("normalization done")
return pp
示例6: process_pipe
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def process_pipe():
parent_conn, child_conn = Pipe()
p = Process(target=pipe_test, args=(child_conn,))
p.start()
print parent_conn.recv()
p.join()
parent_conn.close()
示例7: run
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def run(self):
logging.info('Visualizer thread started')
parent_end, child_end = Pipe()
# Sensible default value for max_process
max_process = 2
process_count = 0
while not self.stop or not self.job_backlog.empty():
while parent_end.poll(0.1):
parent_end.recv() ## currently not using the info... irrelevant
## TODO - a signal to notify the viewer that visuzaliztion job has been finished...
#self.controller.view_update(self)
process_count -= 1
if self.job_backlog.empty():
time.sleep(1)
elif process_count < max_process:
process_count += 1
run_name, function, snapshot = self.job_backlog.get_nowait()
if not (run_name in self.remove_run_name):
logging.info('Added job to visuzalizer Que: ' + str(run_name))
logging.info('No. of jobs in Que: ' + str(process_count))
p = Process(target=self.render_graph,
args=(function, snapshot, run_name, child_end))
p.start()
logging.info('Visualizer Finished')
示例8: onExeBtn
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def onExeBtn(self, event):
srcFiles = self.projPane.getValue()
self.analyzerOutDir = os.path.join(self.projRootDir, 'analyzer_output')
oldcwd = os.getcwd()
if not os.path.exists(self.analyzerOutDir):
os.makedirs(self.analyzerOutDir)
os.chdir(self.analyzerOutDir)
rcv_pipe, snd_pipe = Pipe(duplex=True)
self.dbname = ''.join([self.projRootDir.replace(os.sep, '_').strip('_'), '.sqlite'])
self.exePane.dbPathTc.SetValue(os.path.join(self.analyzerOutDir, self.dbname))
self.exePane.ppLogFileTc.SetValue(os.path.join(self.analyzerOutDir, 'preprocessor.log'))
self.exePane.parserLogFileTc.SetValue(os.path.join(self.analyzerOutDir, 'parser.log'))
p = Process(target=analyze,
args=(snd_pipe,
os.path.join(self.analyzerOutDir, self.dbname),
self.getPpCfg(),
self.getParserCfg(),
srcFiles,
self.exePane.pipelineCb.GetValue(),
self.exePane.numProcSc.GetValue(),
self.exePane.numPpProcSc.GetValue(),
self.exePane.numParserProcSc.GetValue(),
))
p.start()
dlg = wx.ProgressDialog('Executing',
'0/%d' % len(srcFiles),
parent=self,
maximum=len(srcFiles)*10,
style=wx.PD_CAN_ABORT |
wx.PD_APP_MODAL |
wx.PD_ELAPSED_TIME
)
dlg.SetSize((500,150))
dlg.Layout()
dlg.Show()
result = None
while True:
i, total, result = rcv_pipe.recv()
ret = dlg.Update(i*10, result if i == total else '[%d/%d] %s ... done' % (i+1, total, result))
if ret[0] == False:
rcv_pipe.send('STOP')
while result != 'STOPPED':
result = rcv_pipe.recv()
dlg.Update(total*10, 'Canceled')
break
if i == total:
break
p.join()
self.exePane.dbPathTc.SetValue(os.path.join(self.analyzerOutDir, self.dbname))
os.chdir(oldcwd)
示例9: smpScore
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def smpScore(M1,M2,M3,D1SCORE,D2SCORE,D3SCORE,D4SCORE):
st=time.time()
pconn,cconn=Pipe()
qconn,dconn=Pipe()
rconn,econn=Pipe()
nLIST=[]
p=Process(target=smpScoFunction,args=(M1,cconn,D1SCORE,D2SCORE,D3SCORE,D4SCORE))
q=Process(target=smpScoFunction,args=(M2,dconn,D1SCORE,D2SCORE,D3SCORE,D4SCORE))
r=Process(target=smpScoFunction,args=(M3,econn,D1SCORE,D2SCORE,D3SCORE,D4SCORE))
p.start()
q.start()
r.start()
p1LIST=pconn.recv()
p2LIST=qconn.recv()
p3LIST=rconn.recv()
p.join()
q.join()
r.join()
nLIST=p1LIST+p2LIST+p3LIST
et=time.time()
tt=et-st
print 'smp scoring done in '+str(tt)+' seconds.'
return nLIST
示例10: QuickSortMPListArray
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def QuickSortMPListArray(A,conn,NumProcs):
if len(A)<=1 :
conn.send(A)
conn.close()
elif int(NumProcs)<1:
conn.send(QuickSortListArray(A))
conn.close()
else:
lesser=[]
greater=[]
pv=[]
Pivot=A.pop(0)
pvVal=int(Pivot[0])
lesser=[x for x in A if x[0] < pvVal]
greater=[x for x in A if x[0] > pvVal]
pv=[x for x in A if x[0] == pvVal]
pv.append(Pivot)
Procs=int(NumProcs)-1
pConnLeft,cConnLeft=Pipe()
leftProc=Process(target=QuickSortMPListArray,args=(lesser,cConnLeft,Procs))
pConnRight,cConnRight=Pipe()
rightProc=Process(target=QuickSortMPListArray,args=(greater,cConnRight,Procs))
leftProc.start()
rightProc.start()
conn.send(pConnLeft.recv()+pv+pConnRight.recv())
conn.close()
leftProc.join()
rightProc.join()
return
示例11: MMLWorker
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
class MMLWorker(object):
"""Represents the Daemon's connection to the subprocess"""
def __init__(self,runner):
"""Creates and initalizes a subprocess and its connections."""
self.pipe, pipe = Pipe()
self.proc = Process(target=worker, args=(pipe,runner))
self.proc.start();
self.pid = self.proc.pid
def __del__(self):
"""Ensures the subprocess is correctly garbage collected."""
self.pipe.close();
self.proc.terminate();
def pump(self,block=False):
"""Returns a key,val pair from the subprocess, or None,None."""
key,val = None,None
if block:
(key,val) = self.pipe.recv()
elif self.pipe.poll():
(key,val) = self.pipe.recv()
return key,val
def stop(self):
"""Sends the stop signal to the subprocess."""
self.pipe.send(('stop',()))
def pause(self):
"""Sends the pause signal to the subprocess."""
self.pipe.send(('pause',()))
def start(self,program):
"""Sends the start signal to the subprocess."""
self.pipe.send(('start',(program,)))
示例12: test_fork
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def test_fork(self):
# Test using a client before and after a fork.
if sys.platform == "win32":
raise SkipTest("Can't fork on Windows")
try:
from multiprocessing import Process, Pipe
except ImportError:
raise SkipTest("No multiprocessing module")
db = self._get_client().pymongo_test
# Failure occurs if the client is used before the fork
db.test.find_one()
def loop(pipe):
while True:
try:
db.test.insert({"a": "b"})
for _ in db.test.find():
pass
except:
traceback.print_exc()
pipe.send(True)
os._exit(1)
cp1, cc1 = Pipe()
cp2, cc2 = Pipe()
p1 = Process(target=loop, args=(cc1,))
p2 = Process(target=loop, args=(cc2,))
p1.start()
p2.start()
p1.join(1)
p2.join(1)
p1.terminate()
p2.terminate()
p1.join()
p2.join()
cc1.close()
cc2.close()
# recv will only have data if the subprocess failed
try:
cp1.recv()
self.fail()
except EOFError:
pass
try:
cp2.recv()
self.fail()
except EOFError:
pass
db.connection.close()
示例13: _process_image
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def _process_image(self, image):
# Create pipes for process communication
std_size_pipe, std_size_child_end = Pipe()
thumb_pipe, thumb_child_end = Pipe()
# Create the threads
threads = [
Process(
target=self._thumbnail,
args=(image, thumb_child_end, (128, 128))
),
Process(
target=self._thumbnail,
args=(image, std_size_child_end, (1920, 1080))
)
]
# Start threads
for thread in threads:
thread.start()
# Get processed images content and close threads
images_bytes = (
thumb_pipe.recv(), std_size_pipe.recv()
)
for thread in threads:
thread.join()
for obj in images_bytes:
if type(obj) is IOError:
raise obj
return images_bytes
示例14: quicksort
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def quicksort(self,arr, conn, procNum):
if procNum <= 0 or len(arr)<= 1:
conn.send(self.qck(arr))
conn.close()
return
#print 'Just in case you don't trust that this program works better than other quicksorts :3 FUBAR. process id:', os.getppid()
pivot = arr.pop(random.randint(0, len(arr)-1))
leftSide = [x for x in arr if x < pivot]
rightSide = [x for x in arr if x > pivot]
pconnLeft, cconnLeft = Pipe()
leftProc = Process(target= self.quicksort, args=(leftSide, cconnLeft,procNum -1))
pconnRight, cconnRight = Pipe()
rightProc = Process(target=self.quicksort, args=(rightSide, cconnRight, procNum - 1))
leftProc.start()
rightProc.start()
conn.send(pconnLeft.recv() + [pivot] + pconnRight.recv())
conn.close()
leftProc.join()
rightProc.join()
示例15: usage3
# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv [as 别名]
def usage3():
# The Pipe() function returns a pair of connection objects
# connected by a pipe which by default is duplex (two-way)
parent_conn, child_conn = Pipe()
child_conn.send('wenychan3')
child_conn.close()
print parent_conn.recv() # prints "[42, None, 'hello']"