File: os_read_nonblocking.py

package info (click to toggle)
python-eventlet 0.40.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,200 kB
  • sloc: python: 25,101; sh: 78; makefile: 31
file content (30 lines) | stat: -rw-r--r-- 565 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
if __name__ == '__main__':
    import eventlet
    from eventlet.greenthread import sleep, spawn

    eventlet.monkey_patch()

    import signal
    import os

    thread = None
    timed_out = False

    def on_timeout(signum, frame):
        global timed_out
        timed_out = True
        thread.kill()

    def blocking_read(fd):
        os.read(fd, 4096)

    signal.signal(signal.SIGALRM, on_timeout)
    signal.alarm(3)

    read_fd, write_fd = os.pipe()
    thread = spawn(blocking_read, read_fd)
    sleep(0)

    assert not timed_out

    print('pass')