Mercurial > public > mercurial-scm > hg
annotate tests/killdaemons.py @ 52640:24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
These were different classes in py2, but now a handful of error classes are just
an alias of `OSError`, like `IOError`, `EnvironmentError`, `WindowsError`, etc.
This is the result of running a hacked version of `pyupgrade` 3.19.1[1]
$ hg files -0 'relglob:**.py' | xargs -0 \
pyupgrade --py38-plus --keep-percent-format --keep-mock --keep-runtime-typing
The hack is because it doesn't have command line switches to disable most
changes, so it makes tons of unrelated changes all at once. The hack is to
1) patch `pyupgrade._main._fix_tokens()` to immediately return its content arg
2) change `pyupgrade._data.register_decorator()` to only register the function
if it's from the fixer we're interested in:
if func.__module__ in (
"pyupgrade._plugins.exceptions",
):
FUNCS[tp].append(func)
return func
[1] https://github.com/asottile/pyupgrade
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 05 Jan 2025 21:03:17 -0500 |
parents | 23cc79e04c28 |
children |
rev | line source |
---|---|
45830
c102b704edb5
global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
1 #!/usr/bin/env python3 |
7344
58fd3c718ca4
tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 |
28942
05cb9c6f310e
py3: use absolute_import in killdaemons.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
25473
diff
changeset
|
3 import os |
05cb9c6f310e
py3: use absolute_import in killdaemons.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
25473
diff
changeset
|
4 import signal |
05cb9c6f310e
py3: use absolute_import in killdaemons.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
25473
diff
changeset
|
5 import sys |
05cb9c6f310e
py3: use absolute_import in killdaemons.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
25473
diff
changeset
|
6 import time |
7344
58fd3c718ca4
tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
8 if os.name == 'nt': |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
9 import ctypes |
20493
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
10 |
32857
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
11 _BOOL = ctypes.c_long |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
12 _DWORD = ctypes.c_ulong |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
13 _UINT = ctypes.c_uint |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
14 _HANDLE = ctypes.c_void_p |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
15 |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
16 ctypes.windll.kernel32.CloseHandle.argtypes = [_HANDLE] |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
17 ctypes.windll.kernel32.CloseHandle.restype = _BOOL |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
18 |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
19 ctypes.windll.kernel32.GetLastError.argtypes = [] |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
20 ctypes.windll.kernel32.GetLastError.restype = _DWORD |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
21 |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
22 ctypes.windll.kernel32.OpenProcess.argtypes = [_DWORD, _BOOL, _DWORD] |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
23 ctypes.windll.kernel32.OpenProcess.restype = _HANDLE |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
24 |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
25 ctypes.windll.kernel32.TerminateProcess.argtypes = [_HANDLE, _UINT] |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
26 ctypes.windll.kernel32.TerminateProcess.restype = _BOOL |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
27 |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
28 ctypes.windll.kernel32.WaitForSingleObject.argtypes = [_HANDLE, _DWORD] |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
29 ctypes.windll.kernel32.WaitForSingleObject.restype = _DWORD |
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
30 |
20493
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
31 def _check(ret, expectederr=None): |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
32 if ret == 0: |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
33 winerrno = ctypes.GetLastError() |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
34 if winerrno == expectederr: |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
35 return True |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
36 raise ctypes.WinError(winerrno) |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
37 |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
38 def kill(pid, logfn, tryhard=True): |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
39 logfn('# Killing daemon process %d' % pid) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
40 PROCESS_TERMINATE = 1 |
20496
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
41 PROCESS_QUERY_INFORMATION = 0x400 |
20698
1147563faf62
killdaemons: drop superfluous L suffix from constant
Augie Fackler <raf@durin42.com>
parents:
20496
diff
changeset
|
42 SYNCHRONIZE = 0x00100000 |
20494
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
43 WAIT_OBJECT_0 = 0 |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
44 WAIT_TIMEOUT = 258 |
32858
ed1f376090cd
killdaemons: fix WaitForSingleObject() error handling logic on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
32857
diff
changeset
|
45 WAIT_FAILED = _DWORD(0xFFFFFFFF).value |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
46 handle = ctypes.windll.kernel32.OpenProcess( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
47 PROCESS_TERMINATE | SYNCHRONIZE | PROCESS_QUERY_INFORMATION, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
48 False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
49 pid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
50 ) |
32857
d644e859d9da
killdaemons: explicitly set the ctypes signatures
Matt Harbison <matt_harbison@yahoo.com>
parents:
32677
diff
changeset
|
51 if handle is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
52 _check(0, 87) # err 87 when process not found |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
53 return # process not found, already finished |
20493
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
54 try: |
20496
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
55 r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100) |
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
56 if r == WAIT_OBJECT_0: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
57 pass # terminated, but process handle still available |
20496
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
58 elif r == WAIT_TIMEOUT: |
51991
23cc79e04c28
tests: teach `killdaemons` on Windows to use an exit code provided by a caller
Matt Harbison <matt_harbison@yahoo.com>
parents:
51699
diff
changeset
|
59 # Allow the caller to optionally specify the exit code, to |
23cc79e04c28
tests: teach `killdaemons` on Windows to use an exit code provided by a caller
Matt Harbison <matt_harbison@yahoo.com>
parents:
51699
diff
changeset
|
60 # simulate killing with a signal. |
23cc79e04c28
tests: teach `killdaemons` on Windows to use an exit code provided by a caller
Matt Harbison <matt_harbison@yahoo.com>
parents:
51699
diff
changeset
|
61 exit_code = int(os.environ.get("DAEMON_EXITCODE", -1)) |
23cc79e04c28
tests: teach `killdaemons` on Windows to use an exit code provided by a caller
Matt Harbison <matt_harbison@yahoo.com>
parents:
51699
diff
changeset
|
62 _check( |
23cc79e04c28
tests: teach `killdaemons` on Windows to use an exit code provided by a caller
Matt Harbison <matt_harbison@yahoo.com>
parents:
51699
diff
changeset
|
63 ctypes.windll.kernel32.TerminateProcess(handle, exit_code) |
23cc79e04c28
tests: teach `killdaemons` on Windows to use an exit code provided by a caller
Matt Harbison <matt_harbison@yahoo.com>
parents:
51699
diff
changeset
|
64 ) |
32858
ed1f376090cd
killdaemons: fix WaitForSingleObject() error handling logic on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
32857
diff
changeset
|
65 elif r == WAIT_FAILED: |
ed1f376090cd
killdaemons: fix WaitForSingleObject() error handling logic on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
32857
diff
changeset
|
66 _check(0) # err stored in GetLastError() |
20494
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
67 |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
68 # TODO?: forcefully kill when timeout |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
69 # and ?shorter waiting time? when tryhard==True |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
70 r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
71 # timeout = 100 ms |
20494
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
72 if r == WAIT_OBJECT_0: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
73 pass # process is terminated |
20494
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
74 elif r == WAIT_TIMEOUT: |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
75 logfn('# Daemon process %d is stuck') |
32858
ed1f376090cd
killdaemons: fix WaitForSingleObject() error handling logic on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
32857
diff
changeset
|
76 elif r == WAIT_FAILED: |
ed1f376090cd
killdaemons: fix WaitForSingleObject() error handling logic on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
32857
diff
changeset
|
77 _check(0) # err stored in GetLastError() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
78 except: # re-raises |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
79 ctypes.windll.kernel32.CloseHandle(handle) # no _check, keep error |
20493
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
80 raise |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
81 _check(ctypes.windll.kernel32.CloseHandle(handle)) |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
82 |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
83 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
84 |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
85 def kill(pid, logfn, tryhard=True): |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
86 try: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
87 os.kill(pid, 0) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
88 logfn('# Killing daemon process %d' % pid) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
89 os.kill(pid, signal.SIGTERM) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
90 if tryhard: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
91 for i in range(10): |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
92 time.sleep(0.05) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
93 os.kill(pid, 0) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
94 else: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
95 time.sleep(0.1) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
96 os.kill(pid, 0) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
97 logfn('# Daemon process %d is stuck - really killing it' % pid) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
98 os.kill(pid, signal.SIGKILL) |
49309
d54b213c4380
py3: catch ProcessLookupError instead of checking errno == ESRCH
Manuel Jacob <me@manueljacob.de>
parents:
48875
diff
changeset
|
99 except ProcessLookupError: |
d54b213c4380
py3: catch ProcessLookupError instead of checking errno == ESRCH
Manuel Jacob <me@manueljacob.de>
parents:
48875
diff
changeset
|
100 pass |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
101 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
102 |
17464
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
103 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None): |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
104 if not logfn: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
105 logfn = lambda s: s |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
106 # Kill off any leftover daemon processes |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
107 try: |
32677
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
108 pids = [] |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
109 with open(pidfile) as fp: |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
110 for line in fp: |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
111 try: |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
112 pid = int(line) |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
113 if pid <= 0: |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
114 raise ValueError |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
115 except ValueError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
116 logfn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
117 '# Not killing daemon process %s - invalid pid' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
118 % line.rstrip() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
119 ) |
32677
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
120 continue |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
121 pids.append(pid) |
f840b2621cce
killdaemons: close pid file before killing processes
Matt Harbison <matt_harbison@yahoo.com>
parents:
29811
diff
changeset
|
122 for pid in pids: |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
123 kill(pid, logfn, tryhard) |
17464
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
124 if remove: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
125 os.unlink(pidfile) |
52640
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51991
diff
changeset
|
126 except OSError: |
17464
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
127 pass |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
128 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
129 |
17464
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
130 if __name__ == '__main__': |
25473
123c99034cb6
tests: make killdaemons.py use DAEMON_PIDS by default
Matt Mackall <mpm@selenic.com>
parents:
25031
diff
changeset
|
131 if len(sys.argv) > 1: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37846
diff
changeset
|
132 (path,) = sys.argv[1:] |
25473
123c99034cb6
tests: make killdaemons.py use DAEMON_PIDS by default
Matt Mackall <mpm@selenic.com>
parents:
25031
diff
changeset
|
133 else: |
123c99034cb6
tests: make killdaemons.py use DAEMON_PIDS by default
Matt Mackall <mpm@selenic.com>
parents:
25031
diff
changeset
|
134 path = os.environ["DAEMON_PIDS"] |
123c99034cb6
tests: make killdaemons.py use DAEMON_PIDS by default
Matt Mackall <mpm@selenic.com>
parents:
25031
diff
changeset
|
135 |
37846
89793289c891
tests: remove pid file by default
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32858
diff
changeset
|
136 killdaemons(path, remove=True) |