annotate unix.py @ 126:fcdcd0c95552

Fixed the generic implementation of call to use testcases.WallTimeLimitExceeded
author Oleg Oshmyan <chortos@inbox.lv>
date Sun, 15 May 2011 23:14:00 +0100
parents 19c42a3cd962
children f5b8a0c0e3cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
1 # Copyright (c) 2010-2011 Chortos-2 <chortos@inbox.lv>
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
2
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
3 from __future__ import division, with_statement
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
4
91
c62c9bfd614a Removed import_error
Oleg Oshmyan <chortos@inbox.lv>
parents: 86
diff changeset
5 from compat import *
c62c9bfd614a Removed import_error
Oleg Oshmyan <chortos@inbox.lv>
parents: 86
diff changeset
6 import testcases # mutual import
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
7
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
8 from subprocess import Popen
86
8cd7a732f2f3 Fixed a crash in the unix module
Oleg Oshmyan <chortos@inbox.lv>
parents: 85
diff changeset
9 import os, sys, time
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
10
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
11 try:
85
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
12 from testcases import clock
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
13 except ImportError:
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
14 if sys.platform.startswith('java'):
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
15 from time import clock
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
16 else:
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
17 from time import time as clock
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
18
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
19 try:
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
20 from signal import SIGTERM, SIGKILL
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
21 except ImportError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
22 SIGTERM = 15
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
23 SIGKILL = 9
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
24
85
741ae3391b61 Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
25 __all__ = 'call', 'kill', 'terminate', 'pause', 'clock'
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
26
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
27
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
28 if not sys.stdin.isatty():
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
29 pause = lambda: sys.stdin.read(1)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
30 catch_escape = False
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
31 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
32 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
33 from select import select
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
34 import termios, tty, atexit
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
35 except ImportError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
36 pause = None
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
37 catch_escape = False
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
38 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
39 catch_escape = True
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
40 def cleanup(old=termios.tcgetattr(sys.stdin.fileno())):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
41 termios.tcsetattr(sys.stdin.fileno(), termios.TCSAFLUSH, old)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
42 atexit.register(cleanup)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
43 tty.setcbreak(sys.stdin.fileno())
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
44 def pause():
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
45 sys.stdin.read(1)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
46
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
47 try:
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
48 from signal import SIGCHLD, SIG_DFL, signal, set_wakeup_fd
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
49 from select import select, error as SelectError
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
50 from errno import EAGAIN, EINTR
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
51 from fcntl import fcntl, F_SETFD, F_GETFD, F_SETFL, F_GETFL
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
52 from os import O_NONBLOCK
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
53 try:
124
19c42a3cd962 Very fast testees no longer break Popen on some UNIX systems on Python 2.6+
Oleg Oshmyan <chortos@inbox.lv>
parents: 123
diff changeset
54 from signal import siginterrupt
19c42a3cd962 Very fast testees no longer break Popen on some UNIX systems on Python 2.6+
Oleg Oshmyan <chortos@inbox.lv>
parents: 123
diff changeset
55 except ImportError:
19c42a3cd962 Very fast testees no longer break Popen on some UNIX systems on Python 2.6+
Oleg Oshmyan <chortos@inbox.lv>
parents: 123
diff changeset
56 # Sucks.
19c42a3cd962 Very fast testees no longer break Popen on some UNIX systems on Python 2.6+
Oleg Oshmyan <chortos@inbox.lv>
parents: 123
diff changeset
57 siginterrupt = lambda signalnum, flag: None
19c42a3cd962 Very fast testees no longer break Popen on some UNIX systems on Python 2.6+
Oleg Oshmyan <chortos@inbox.lv>
parents: 123
diff changeset
58 try:
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
59 import cPickle as pickle
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
60 except ImportError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
61 import pickle
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
62 except ImportError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
63 def call(*args, **kwargs):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
64 case = kwargs.pop('case')
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
65 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
66 case.process = Popen(*args, **kwargs)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
67 except OSError:
94
b7fb64ce03d9 Fixed a couple of bugs
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
68 raise testcases.CannotStartTestee(sys.exc_info()[1])
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
69 case.time_started = clock()
100
995502cdafc6 Fixed the generic implementation of call to use maxwalltime
Oleg Oshmyan <chortos@inbox.lv>
parents: 94
diff changeset
70 if not case.maxwalltime:
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
71 while True:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
72 exitcode, now = case.process.poll(), clock()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
73 if exitcode is not None:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
74 case.time_stopped = now
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
75 break
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
76 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
77 time.sleep(.001)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
78 else:
100
995502cdafc6 Fixed the generic implementation of call to use maxwalltime
Oleg Oshmyan <chortos@inbox.lv>
parents: 94
diff changeset
79 time_end = case.time_started + case.maxwalltime
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
80 while True:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
81 exitcode, now = case.process.poll(), clock()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
82 if exitcode is not None:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
83 case.time_stopped = now
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
84 break
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
85 elif now >= time_end:
126
fcdcd0c95552 Fixed the generic implementation of call to use testcases.WallTimeLimitExceeded
Oleg Oshmyan <chortos@inbox.lv>
parents: 124
diff changeset
86 raise testcases.WallTimeLimitExceeded
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
87 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
88 time.sleep(.001)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
89 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
90 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
91 from fcntl import FD_CLOEXEC
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
92 except ImportError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
93 FD_CLOEXEC = 1
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
94
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
95 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
96 from resource import getrusage, RUSAGE_SELF, RUSAGE_CHILDREN
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
97 except ImportError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
98 from time import clock as cpuclock
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
99 getrusage = lambda who: None
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
100 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
101 def cpuclock():
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
102 rusage = getrusage(RUSAGE_SELF)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
103 return rusage.ru_utime + rusage.ru_stime
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
104
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
105 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
106 from resource import setrlimit
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
107 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
108 from resource import RLIMIT_AS
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
109 except ImportError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
110 from resource import RLIMIT_VMEM
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
111 except ImportError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
112 setrlimit = None
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
113
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
114 # Make SIGCHLD interrupt sleep() and select()
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
115 sigchld_pipe_read, sigchld_pipe_write = os.pipe()
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
116 fcntl(sigchld_pipe_read, F_SETFL,
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
117 fcntl(sigchld_pipe_read, F_GETFL) | O_NONBLOCK)
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
118 fcntl(sigchld_pipe_write, F_SETFL,
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
119 fcntl(sigchld_pipe_write, F_GETFL) | O_NONBLOCK)
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
120 def bury_child(signum, frame):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
121 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
122 bury_child.case.time_stopped = clock()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
123 except Exception:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
124 pass
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
125 signal(SIGCHLD, bury_child)
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
126 set_wakeup_fd(sigchld_pipe_write)
108
218b8c28549c Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents: 100
diff changeset
127 class SignalIgnorer(object):
218b8c28549c Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents: 100
diff changeset
128 def __enter__(self):
218b8c28549c Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents: 100
diff changeset
129 signal(SIGCHLD, SIG_DFL)
218b8c28549c Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents: 100
diff changeset
130 def __exit__(self, exc_type, exc_value, traceback):
218b8c28549c Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents: 100
diff changeset
131 signal(SIGCHLD, bury_child)
218b8c28549c Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents: 100
diff changeset
132 signal_ignorer = SignalIgnorer()
218b8c28549c Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents: 100
diff changeset
133 __all__ += 'signal_ignorer',
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
134
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
135 # If you want this to work portably, don't set any stdio argument to PIPE
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
136 def call(*args, **kwargs):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
137 global last_rusage
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
138 bury_child.case = case = kwargs.pop('case')
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
139 read, write = os.pipe()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
140 fcntl(write, F_SETFD, fcntl(write, F_GETFD) | FD_CLOEXEC)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
141 def preexec_fn():
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
142 os.close(read)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
143 if setrlimit and case.maxmemory:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
144 maxmemory = ceil(case.maxmemory * 1048576)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
145 setrlimit(RLIMIT_AS, (maxmemory, maxmemory))
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
146 # I would also set a CPU time limit but I do not want the time
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
147 # passing between the calls to fork and exec to be counted in
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
148 os.write(write, pickle.dumps((clock(), cpuclock()), 1))
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
149 kwargs['preexec_fn'] = preexec_fn
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
150 old_rusage = getrusage(RUSAGE_CHILDREN)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
151 last_rusage = None
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
152 while True:
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
153 try:
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
154 os.read(sigchld_pipe_read, 512)
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
155 except OSError:
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
156 if sys.exc_info()[1].errno == EAGAIN:
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
157 break
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
158 else:
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
159 raise
124
19c42a3cd962 Very fast testees no longer break Popen on some UNIX systems on Python 2.6+
Oleg Oshmyan <chortos@inbox.lv>
parents: 123
diff changeset
160 siginterrupt(SIGCHLD, False)
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
161 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
162 case.process = Popen(*args, **kwargs)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
163 except OSError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
164 os.close(read)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
165 raise testcases.CannotStartTestee(sys.exc_info()[1])
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
166 finally:
124
19c42a3cd962 Very fast testees no longer break Popen on some UNIX systems on Python 2.6+
Oleg Oshmyan <chortos@inbox.lv>
parents: 123
diff changeset
167 siginterrupt(SIGCHLD, True)
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
168 os.close(write)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
169 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
170 if not catch_escape:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
171 if case.maxwalltime:
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
172 try:
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
173 select((sigchld_pipe_read,), (), (), case.maxwalltime)
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
174 except SelectError:
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
175 if sys.exc_info()[1].args[0] != EINTR:
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
176 raise
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
177 if case.process.poll() is None:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
178 raise testcases.WallTimeLimitExceeded
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
179 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
180 case.process.wait()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
181 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
182 if not case.maxwalltime:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
183 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
184 while case.process.poll() is None:
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
185 s = select((sys.stdin, sigchld_pipe_read), (), ())
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
186 if (sigchld_pipe_read not in s[0] and
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
187 sys.stdin.read(1) == '\33'):
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
188 raise testcases.CanceledByUser
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
189 except (SelectError, IOError):
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
190 if sys.exc_info()[1].args[0] != EINTR:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
191 raise
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
192 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
193 case.process.poll()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
194 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
195 time_end = clock() + case.maxwalltime
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
196 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
197 while case.process.poll() is None:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
198 remaining = time_end - clock()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
199 if remaining > 0:
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
200 s = select((sys.stdin, sigchld_pipe_read),
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
201 (), (), remaining)
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
202 if (sigchld_pipe_read not in s[0] and
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
203 sys.stdin.read(1) == '\33'):
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
204 raise testcases.CanceledByUser
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
205 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
206 raise testcases.WallTimeLimitExceeded
118
16fe21d6582e Fixed a few race conditions in unix.call triggered by very fast testees
Oleg Oshmyan <chortos@inbox.lv>
parents: 108
diff changeset
207 except (SelectError, IOError):
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
208 if sys.exc_info()[1].args[0] != EINTR:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
209 raise
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
210 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
211 case.process.poll()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
212 finally:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
213 case.time_started, cpustart = pickle.loads(os.read(read, 512))
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
214 os.close(read)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
215 del bury_child.case
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
216 new_rusage = getrusage(RUSAGE_CHILDREN)
119
0b265fe9c81f Wall-clock time limit is now enforced on the output wall-clock time
Oleg Oshmyan <chortos@inbox.lv>
parents: 118
diff changeset
217 if (case.maxwalltime and
0b265fe9c81f Wall-clock time limit is now enforced on the output wall-clock time
Oleg Oshmyan <chortos@inbox.lv>
parents: 118
diff changeset
218 case.time_stopped - case.time_started > case.maxwalltime):
0b265fe9c81f Wall-clock time limit is now enforced on the output wall-clock time
Oleg Oshmyan <chortos@inbox.lv>
parents: 118
diff changeset
219 raise testcases.WallTimeLimitExceeded
123
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
220 if new_rusage:
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
221 time_started = old_rusage.ru_utime + old_rusage.ru_stime + cpustart
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
222 time_stopped = new_rusage.ru_utime + new_rusage.ru_stime
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
223 if case.maxcputime or not case.maxwalltime:
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
224 case.time_started = time_started
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
225 case.time_stopped = time_stopped
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
226 case.time_limit_string = case.cpu_time_limit_string
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
227 if (case.maxcputime and
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
228 time_stopped - time_started > case.maxcputime):
90c002c960cb Fixed CPU time display on UNIX
Oleg Oshmyan <chortos@inbox.lv>
parents: 119
diff changeset
229 raise testcases.CPUTimeLimitExceeded
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
230 if case.maxmemory:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
231 if sys.platform != 'darwin':
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
232 maxrss = case.maxmemory * 1024
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
233 else:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
234 maxrss = case.maxmemory * 1048576
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
235 if last_rusage and last_rusage.ru_maxrss > maxrss:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
236 raise testcases.MemoryLimitExceeded
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
237 elif (new_rusage and
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
238 new_rusage.ru_maxrss > old_rusage.ru_maxrss and
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
239 new_rusage.ru_maxrss > maxrss):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
240 raise testcases.MemoryLimitExceeded
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
241
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
242 # Emulate memory limits on platforms compatible with 4.3BSD but not XSI
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
243 # I say 'emulate' because the OS will allow excessive memory usage
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
244 # anyway; Upreckon will just treat the test case as not passed.
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
245 # To do this, we not only require os.wait4 to be present but also
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
246 # assume things about the implementation of subprocess.Popen.
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
247 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
248 def waitpid_emu(pid, options, _wait4=os.wait4):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
249 global last_rusage
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
250 pid, status, last_rusage = _wait4(pid, options)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
251 return pid, status
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
252 _waitpid = os.waitpid
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
253 os.waitpid = waitpid_emu
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
254 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
255 defaults = Popen._internal_poll.__func__.__defaults__
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
256 except AttributeError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
257 # Python 2.5
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
258 defaults = Popen._internal_poll.im_func.func_defaults
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
259 i = defaults.index(_waitpid)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
260 defaults = defaults[:i] + (waitpid_emu,) + defaults[i+1:]
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
261 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
262 Popen._internal_poll.__func__.__defaults__ = defaults
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
263 except AttributeError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
264 # Python 2.5 again
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
265 Popen._internal_poll.im_func.func_defaults = defaults
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
266 except (AttributeError, ValueError):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
267 pass
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
268
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
269
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
270 def kill(process):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
271 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
272 process.kill()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
273 except AttributeError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
274 os.kill(process.pid, SIGKILL)
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
275
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
276
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
277 def terminate(process):
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
278 try:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
279 process.terminate()
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
280 except AttributeError:
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
281 os.kill(process.pid, SIGTERM)