Mercurial > ~astiob > upreckon > hgweb
comparison win32.py @ 134:e84f33a60a5c
Moved process killing logic into platform-specific modules
| author | Oleg Oshmyan <chortos@inbox.lv> |
|---|---|
| date | Fri, 20 May 2011 14:47:42 +0100 |
| parents | 7923faf392fe |
| children | 388ae061c915 |
comparison
equal
deleted
inserted
replaced
| 133:a9d2aa6810c7 | 134:e84f33a60a5c |
|---|---|
| 45 __getnewargs__ = lambda self: tuple(self) | 45 __getnewargs__ = lambda self: tuple(self) |
| 46 kernel, user = (property(itemgetter(i)) for i in (0, 1)) | 46 kernel, user = (property(itemgetter(i)) for i in (0, 1)) |
| 47 else: | 47 else: |
| 48 ProcessTimes = namedtuple('ProcessTimes', 'kernel user') | 48 ProcessTimes = namedtuple('ProcessTimes', 'kernel user') |
| 49 | 49 |
| 50 __all__ = 'call', 'kill', 'terminate', 'wait', 'pause', 'clock' | 50 __all__ = 'call', 'kill', 'pause', 'clock' |
| 51 | 51 |
| 52 | 52 |
| 53 from functools import wraps | 53 from functools import wraps |
| 54 pathext = [''] + os.environ['PATHEXT'].split(';') | 54 pathext = [''] + os.environ['PATHEXT'].split(';') |
| 55 @wraps(subprocess.Popen) | 55 @wraps(subprocess.Popen) |
| 85 # on the very first try, but syntax differences preclude me from | 85 # on the very first try, but syntax differences preclude me from |
| 86 # doing so in Python 2 and it can't be done at all in Python 3 | 86 # doing so in Python 2 and it can't be done at all in Python 3 |
| 87 raise | 87 raise |
| 88 | 88 |
| 89 | 89 |
| 90 # Automatically convert _subprocess handle objects into low-level HANDLEs | 90 # Automatically convert _subprocess handle objects into low-level |
| 91 # and replicate their functionality for our own use | 91 # HANDLEs and replicate their functionality for our own use |
| 92 try: | 92 try: |
| 93 _subprocess_handle = type(GetCurrentProcess()) | 93 _subprocess_handle = type(GetCurrentProcess()) |
| 94 except NameError: | 94 except NameError: |
| 95 _subprocess_handle = Integral | 95 _subprocess_handle = Integral |
| 96 class Handle(object): | 96 class Handle(object): |
| 539 if counters.PeakPagefileUsage > case.maxmemory * 1048576: | 539 if counters.PeakPagefileUsage > case.maxmemory * 1048576: |
| 540 raise testcases.MemoryLimitExceeded | 540 raise testcases.MemoryLimitExceeded |
| 541 | 541 |
| 542 | 542 |
| 543 def kill(process): | 543 def kill(process): |
| 544 try: | 544 # Give up after three attempts |
| 545 process.terminate() | 545 for i in range(3): |
| 546 except AttributeError: | 546 try: |
| 547 TerminateProcess(process._handle, 1) | 547 try: |
| 548 terminate = kill | 548 process.terminate() |
| 549 wait = subprocess.Popen.wait | 549 except AttributeError: |
| 550 TerminateProcess(process._handle, 1) | |
| 551 except WindowsError: | |
| 552 time.sleep(0) | |
| 553 else: | |
| 554 break |
