This repository has been archived by the owner on Nov 19, 2018. It is now read-only.
/
benchmark_pool_q.py
74 lines (61 loc) · 1.98 KB
/
benchmark_pool_q.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
import sys
import numpy as np
from time import time
from process_tom.process_popen import ExecProcess
from multiprocessing import Queue, Pipe
STOP = 27042
def bench_client(chan, info):
out = False
STOP = chan.load()
qout = chan.load()
while not out:
msg = qout.recv()
out = msg == STOP
print('{} have msg: '.format(info['idx']), msg,
'I will go now' if out else '')
chan.close()
print("Child closing")
sys.exit(0)
def bench_parent(backend=None, strat='string'):
# Launch a child process
proc1 = ExecProcess(func=bench_client, backend=backend)
proc2 = ExecProcess(func=bench_client, backend=backend)
proc1.dump(STOP)
proc2.dump(STOP)
cout, cin = Pipe()
proc1.dump(cout)
proc2.dump(cout)
print("Parent start")
cout.send('hello')
for i in range(10):
cout.send('world')
cout.send(STOP)
cout.send(STOP)
proc1.close()
proc2.close()
if __name__ == '__main__':
import multiprocessing
import argparse
parser = argparse.ArgumentParser('Benchmark for the subprocess pipe')
parser.add_argument('--size', type=int, default=500,
help='Size of the transfert array in MB')
parser.add_argument('--backend', type=str, default=None,
help='Select the backend')
parser.add_argument('--strat', type=str, default='string',
help='Select the backend')
parser.add_argument('--start', type=str, default='forkserver',
help='Set the start method for multiprocessing')
args = parser.parse_args()
# Create the subprocess
multiprocessing.set_start_method(args.start)
try:
bench_parent(args.backend, args.strat)
except Exception as e:
print('\n\n'+'-'*80)
print('Process 0 failed with trace: ')
print('-'*80)
import traceback
print(traceback.format_exc())
print('\n'+'-'*80)
sys.exit(0)