MCPcopy Index your code
hub / github.com/python/cpython / test

Function test

Doc/includes/mp_workers.py:40–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38#
39
40def test():
41 NUMBER_OF_PROCESSES = 4
42 TASKS1 = [(mul, (i, 7)) for i in range(20)]
43 TASKS2 = [(plus, (i, 8)) for i in range(10)]
44
45 # Create queues
46 task_queue = Queue()
47 done_queue = Queue()
48
49 # Submit tasks
50 for task in TASKS1:
51 task_queue.put(task)
52
53 # Start worker processes
54 for i in range(NUMBER_OF_PROCESSES):
55 Process(target=worker, args=(task_queue, done_queue)).start()
56
57 # Get and print results
58 print('Unordered results:')
59 for i in range(len(TASKS1)):
60 print('\t', done_queue.get())
61
62 # Add more tasks using `put()`
63 for task in TASKS2:
64 task_queue.put(task)
65
66 # Get and print some more results
67 for i in range(len(TASKS2)):
68 print('\t', done_queue.get())
69
70 # Tell child processes to stop
71 for i in range(NUMBER_OF_PROCESSES):
72 task_queue.put('STOP')
73
74
75if __name__ == '__main__':

Callers 1

mp_workers.pyFile · 0.70

Calls 5

putMethod · 0.95
getMethod · 0.95
QueueClass · 0.90
ProcessClass · 0.90
startMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…