1 | n/a | import multiprocessing, sys |
---|
2 | n/a | |
---|
3 | n/a | def foo(): |
---|
4 | n/a | print("123") |
---|
5 | n/a | |
---|
6 | n/a | # Because "if __name__ == '__main__'" is missing this will not work |
---|
7 | n/a | # correctly on Windows. However, we should get a RuntimeError rather |
---|
8 | n/a | # than the Windows equivalent of a fork bomb. |
---|
9 | n/a | |
---|
10 | n/a | if len(sys.argv) > 1: |
---|
11 | n/a | multiprocessing.set_start_method(sys.argv[1]) |
---|
12 | n/a | else: |
---|
13 | n/a | multiprocessing.set_start_method('spawn') |
---|
14 | n/a | |
---|
15 | n/a | p = multiprocessing.Process(target=foo) |
---|
16 | n/a | p.start() |
---|
17 | n/a | p.join() |
---|
18 | n/a | sys.exit(p.exitcode) |
---|