Debian Codegraph @

tests/isolated/fork_in_thread.py

raw
1 import eventlet
2
3 eventlet.monkey_patch()
4
5 import os
6 import time
7 import threading
8
9 results = []
10 parent = True
11
12
13 def check_current():
14 if threading.current_thread() not in threading.enumerate():
15 raise SystemExit(17)
16
17
18 def background():
19 time.sleep(1)
20 check_current()
21 results.append(True)
22
23
24 def forker():
25 pid = os.fork()
26 check_current()
27 if pid != 0:
28 # We're in the parent. Wait for child to die.
29 wait_pid, status = os.wait()
30 exit_code = os.waitstatus_to_exitcode(status)
31 assert wait_pid == pid
32 assert exit_code == 0, exit_code
33 else:
34 global parent
35 parent = False
36 results.append(True)
37
38
39 t = threading.Thread(target=background)
40 t.start()
41 t2 = threading.Thread(target=forker)
42 t2.start()
43 t2.join()
44 t.join()
45
46 check_current()
47 assert results == [True, True]
48 if parent:
49 print("pass")