##// END OF EJS Templates
interfaces: make `dirstate` Protocol class methods abstract...
interfaces: make `dirstate` Protocol class methods abstract Now all known Protocol methods that should be implemented by the subclass are abstract. See cdd4bc69bfc1 for details. Note that this will break the `git` extension more, because there are a bunch of methods that aren't implemented that should be, in favor of some very old methods that won't be called (like `add()` and `drop()`). It's already broken, so I'm not taking the time to figure out how to modernize it right now. It's not detected by pytype because the only instantiation of `gitdirstate` is in `git/__init__.py`, which was already excluded from pytype checking for some other reason. AT least with this, it 1) doesn't get forgotten about, and 2) will require changing the interface if/when the core dirstate class evolves.

File last commit:

r53247:d4e30c15 default
r53405:2ac368d0 default
Show More
ps_util.py
53 lines | 1.3 KiB | text/x-python | PythonLexer
# This python code can be imported into tests in order to terminate a process
# with signal.SIGKILL on posix, or a roughly equivalent procedure on Windows.
from __future__ import annotations
import os
import signal
import subprocess
import sys
import tempfile
from .. import (
encoding,
pycompat,
)
from ..utils import procutil
def kill_nt(pid: int, exit_code: int):
fd, pidfile = tempfile.mkstemp(
prefix=b"sigkill-", dir=encoding.environ[b"HGTMP"], text=False
)
try:
os.write(fd, b'%d\n' % pid)
finally:
os.close(fd)
env = dict(encoding.environ)
env[b"DAEMON_EXITCODE"] = b"%d" % exit_code
# Simulate the message written to stderr for this process on non-Windows
# platforms, for test consistency.
print("Killed!", file=sys.stderr)
subprocess.run(
[
encoding.environ[b"PYTHON"],
b"%s/killdaemons.py"
% encoding.environ[b'RUNTESTDIR_FORWARD_SLASH'],
pidfile,
],
env=procutil.tonativeenv(env),
)
def kill(pid: int):
"""Kill the process with the given PID with SIGKILL or equivalent."""
if pycompat.iswindows:
exit_code = 128 + 9
kill_nt(pid, exit_code)
else:
os.kill(pid, signal.SIGKILL)