This file is indexed.

/usr/lib/python3/dist-packages/pyutilib/th/nose_timeout.py is in python3-pyutilib 5.3.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""This module defines a nose plugin to terminate a test after a
specified number of seconds.

Use the following command-line option with nosetests ::

    nosetests --test-timeout=###

"""

__all__ = ['Timeout', 'TestTimeout']

import os
import signal
from nose.plugins.base import Plugin
try:
    from psutil import Process
    _psutil_avail = True
except ImportError:
    _psutil_avail = False
except NotImplementedError:
    _psutil_avail = False

class Timeout(Exception): pass


class TestTimeout(Plugin):
    """Kill tests if they exceed the specified timeout."""
    name = 'timeout'
    score = 5000  # Run early

    def options(self, parser, env):
        """Register command-line options."""
        parser.add_option("--test-timeout", action="store",
                          default=env.get('NOSE_TEST_TIMEOUT', 0),
                          dest="test_timeout",
                          metavar="SECONDS",
                          help="A per-test timeout (in seconds). "
                          "[NOSE_TEST_TIMEOUT]")

    def configure(self, options, config):
        self.timeout = int(options.test_timeout)
        self.enabled = self.timeout > 0
        if self.enabled and not _psutil_avail:
            self.enabled = False
            raise ImportError("The nose Timeout plugin requires the psutil package.")

    def startTest(self, test):
        signal.signal(signal.SIGALRM, self._killTest)
        signal.alarm(self.timeout)

    def stopTest(self, test):
        signal.alarm(0)

    def _all_children(self, p):
        ans = p.get_children()
        i = 0;
        while i < len(ans):
            ans.extend(self._all_children(ans[i]))
            i += 1
        return ans;

    def _killTest(self, signum, frame):
        for p in self._all_children(Process(os.getpid())):
            try:
                p.kill()
            except:
                pass
        hour = int(self.timeout / 3600)
        min = int(self.timeout / 60) - hour*60
        sec = self.timeout % 60
        txt = ""
        if hour:
            txt = "%d hour%s" % (hour, hour > 1 and "s" or "")
        if min:
            if txt:
                txt += ", "
            txt += "%d minute%s" % (min, min > 1 and "s" or "")
        if sec:
            if txt:
                txt += ", "
            txt += "%d second%s" % (sec, sec > 1 and "s" or "")
        raise Timeout("Test exceeded timeout (%s)" % txt)