Debian Codegraph @

tests/isolated/os_read_nonblocking.py

raw
1 if __name__ == '__main__':
2 import eventlet
3 from eventlet.greenthread import sleep, spawn
4
5 eventlet.monkey_patch()
6
7 import signal
8 import os
9
10 thread = None
11 timed_out = False
12
13 def on_timeout(signum, frame):
14 global timed_out
15 timed_out = True
16 thread.kill()
17
18 def blocking_read(fd):
19 os.read(fd, 4096)
20
21 signal.signal(signal.SIGALRM, on_timeout)
22 signal.alarm(3)
23
24 read_fd, write_fd = os.pipe()
25 thread = spawn(blocking_read, read_fd)
26 sleep(0)
27
28 assert not timed_out
29
30 print('pass')