File: test_select_signal.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (51 lines) | stat: -rw-r--r-- 1,620 bytes parent folder | download | duplicates (3)
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
49
50
51
import pytest
import sys

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

    @pytest.mark.skipif(sys.platform=="win32", reason="not supported on windows")
    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