| 1 |
import eventlet |
| 2 |
|
| 3 |
eventlet.monkey_patch() |
| 4 |
|
| 5 |
import os |
| 6 |
import time |
| 7 |
import threading |
| 8 |
|
| 9 |
results = set() |
| 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.add("background") |
| 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.add("forker") |
| 37 |
|
| 38 |
|
| 39 |
t = threading.Thread(target=background) |
| 40 |
t.start() |
| 41 |
forker() |
| 42 |
t.join() |
| 43 |
|
| 44 |
check_current() |
| 45 |
assert results == {"background", "forker"}, results |
| 46 |
if parent: |
| 47 |
print("pass") |