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