File: mp_fork_bomb.py

package info (click to toggle)
python3.4 3.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 80,356 kB
  • ctags: 100,540
  • sloc: python: 459,698; ansic: 381,519; sh: 17,599; asm: 14,322; makefile: 2,209; objc: 761; lisp: 502; exp: 499; cpp: 353; pascal: 80; xml: 73; csh: 21
file content (18 lines) | stat: -rw-r--r-- 448 bytes parent folder | download | duplicates (25)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import multiprocessing, sys

def foo():
    print("123")

# Because "if __name__ == '__main__'" is missing this will not work
# correctly on Windows.  However, we should get a RuntimeError rather
# than the Windows equivalent of a fork bomb.

if len(sys.argv) > 1:
    multiprocessing.set_start_method(sys.argv[1])
else:
    multiprocessing.set_start_method('spawn')

p = multiprocessing.Process(target=foo)
p.start()
p.join()
sys.exit(p.exitcode)