File: test_select_signal.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (48 lines) | stat: -rw-r--r-- 1,513 bytes parent folder | download | duplicates (2)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

class AppTestSelectSignal:
    spaceconfig = {
        "usemodules": ['select', 'time', 'signal'],
    }

    def test_pep475_retry(self):
        import select, time
        import _signal as signal

        def foo(*args):
            signalled.append("ALARM")

        # a list of functions that will do nothing more than sleep for 3
        # seconds
        cases = [(select.select, [], [], [], 3.0)]

        if hasattr(select, 'poll'):
            import posix
            poll = select.poll()
            cases.append((poll.poll, 3000))    # milliseconds

        if hasattr(select, 'epoll'):
            epoll = select.epoll()
            cases.append((epoll.poll, 3.0))

        if hasattr(select, 'kqueue'):
            kqueue = select.kqueue()
            cases.append((kqueue.control, [], 1, 3.0))

        if hasattr(select, 'devpoll'):
            raise NotImplementedError("write this test if we have devpoll")

        for wait_for_three_seconds in cases:
            print(wait_for_three_seconds[0])
            signalled = []
            signal.signal(signal.SIGALRM, foo)
            try:
                t1 = time.time()
                signal.alarm(1)
                wait_for_three_seconds[0](*wait_for_three_seconds[1:])
                t2 = time.time()
            finally:
                signal.signal(signal.SIGALRM, signal.SIG_DFL)

            print("result: signalled = %r in %s seconds" % (signalled, t2 - t1))
            assert signalled != []
            assert t2 - t1 > 2.99