summaryrefslogtreecommitdiffstats
path: root/Lib/test/_test_venv_multiprocessing.py
blob: ad985dd8d56bb4b009e6b40cf6dae21360af41a4 (plain)
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
import multiprocessing
import random
import sys

def fill_queue(queue, code):
    queue.put(code)


def drain_queue(queue, code):
    if code != queue.get():
        sys.exit(1)


def test_func():
    code = random.randrange(0, 1000)
    queue = multiprocessing.Queue()
    fill_pool = multiprocessing.Process(
        target=fill_queue,
        args=(queue, code)
    )
    drain_pool = multiprocessing.Process(
        target=drain_queue,
        args=(queue, code)
    )
    drain_pool.start()
    fill_pool.start()
    fill_pool.join()
    drain_pool.join()


def main():
    multiprocessing.set_start_method('spawn')
    test_pool = multiprocessing.Process(target=test_func)
    test_pool.start()
    test_pool.join()
    sys.exit(test_pool.exitcode)


if __name__ == "__main__":
    main()