| 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_write(fd): |
| 19 |
# once the write buffer is filled up, it should go to sleep instead of blocking |
| 20 |
# write 1 byte at a time as writing large data will block |
| 21 |
# even if select/poll claims otherwise |
| 22 |
for i in range(1, 1000000): |
| 23 |
os.write(fd, b'\0') |
| 24 |
|
| 25 |
signal.signal(signal.SIGALRM, on_timeout) |
| 26 |
signal.alarm(5) |
| 27 |
|
| 28 |
read_fd, write_fd = os.pipe() |
| 29 |
thread = spawn(blocking_write, write_fd) |
| 30 |
# 2 secs is enough time for write buffer to fill up |
| 31 |
sleep(2) |
| 32 |
|
| 33 |
assert not timed_out |
| 34 |
|
| 35 |
print('pass') |