File: xtest__benchmarks.py

package info (click to toggle)
python-gevent 1.0.1-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,948 kB
  • ctags: 12,954
  • sloc: python: 39,061; ansic: 26,289; sh: 13,582; makefile: 833; awk: 18
file content (65 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download
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
# testrunner timeout: 300
import sys
import glob
import subprocess
import time


TIMEOUT = 30


def kill(popen):
    if popen.poll() is not None:
        return
    try:
        popen.kill()
    except OSError, ex:
        if ex.errno == 3:  # No such process
            return
        if ex.errno == 13:  # Permission denied (translated from windows error 5: "Access is denied")
            return
        raise


def wait(popen):
    end = time.time() + TIMEOUT
    while popen.poll() is None:
        if time.time() > end:
            kill(popen)
            popen.wait()
            return 'TIMEOUT'
        time.sleep(0.1)
    return popen.poll()


def system(command):
    popen = subprocess.Popen(command, shell=False)
    try:
        return wait(popen)
    finally:
        kill(popen)


modules = set()

for path in glob.glob('bench_*.py'):
    modules.add(path)

if __name__ == '__main__':
    assert modules

    errors = []

    for path in modules:
        sys.stderr.write(path + '\n')
        sys.stdout.flush()
        command = [sys.executable, '-u', path, 'all']
        res = system(command)
        if res:
            error = '%r failed with %s' % (' '.join(command), res)
            sys.stderr.write(error + '\n')
            errors.append(error)
        sys.stderr.write('-----\n\n')

    if errors:
        sys.exit('\n'.join(errors))