| 1 |
import multiprocessing |
| 2 |
import random |
| 3 |
import sys |
| 4 |
|
| 5 |
def fill_queue(queue, code): |
| 6 |
queue.put(code) |
| 7 |
|
| 8 |
|
| 9 |
def drain_queue(queue, code): |
| 10 |
if code != queue.get(): |
| 11 |
sys.exit(1) |
| 12 |
|
| 13 |
|
| 14 |
def test_func(): |
| 15 |
code = random.randrange(0, 1000) |
| 16 |
queue = multiprocessing.Queue() |
| 17 |
fill_pool = multiprocessing.Process( |
| 18 |
target=fill_queue, |
| 19 |
args=(queue, code) |
| 20 |
) |
| 21 |
drain_pool = multiprocessing.Process( |
| 22 |
target=drain_queue, |
| 23 |
args=(queue, code) |
| 24 |
) |
| 25 |
drain_pool.start() |
| 26 |
fill_pool.start() |
| 27 |
fill_pool.join() |
| 28 |
drain_pool.join() |
| 29 |
|
| 30 |
|
| 31 |
def main(): |
| 32 |
multiprocessing.set_start_method('spawn') |
| 33 |
test_pool = multiprocessing.Process(target=test_func) |
| 34 |
test_pool.start() |
| 35 |
test_pool.join() |
| 36 |
sys.exit(test_pool.exitcode) |
| 37 |
|
| 38 |
|
| 39 |
if __name__ == "__main__": |
| 40 |
main() |