Skip to content

Commit

Permalink
gateway_io: remove Python 2 compat code
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt authored and bluetech committed Apr 26, 2023
1 parent 44fd96e commit 844b3da
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions execnet/gateway_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,12 @@ def kill(self):

def killpopen(popen):
try:
if hasattr(popen, "kill"):
popen.kill()
else:
killpid(popen.pid)
except OSError:
sys.stderr.write("ERROR killing: %s\n" % (sys.exc_info()[1]))
popen.kill()
except OSError as e:
sys.stderr.write("ERROR killing: %s\n" % e)
sys.stderr.flush()


def killpid(pid):
if hasattr(os, "kill"):
os.kill(pid, 15)
elif sys.platform == "win32" or getattr(os, "_name", None) == "nt":
import ctypes

PROCESS_TERMINATE = 1
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)
ctypes.windll.kernel32.TerminateProcess(handle, -1)
ctypes.windll.kernel32.CloseHandle(handle)
else:
raise OSError(f"no method to kill {pid}")


popen_bootstrapline = "import sys;exec(eval(sys.stdin.readline()))"


Expand All @@ -72,10 +55,8 @@ def shell_split_path(path):
def popen_args(spec):
args = shell_split_path(spec.python) if spec.python else [sys.executable]
args.append("-u")
if spec is not None and spec.dont_write_bytecode:
if spec.dont_write_bytecode:
args.append("-B")
# Slight gymnastics in ordering these arguments because CPython (as of
# 2.7.1) ignores -B if you provide `python -c "something" -B`
args.extend(["-c", popen_bootstrapline])
return args

Expand Down

0 comments on commit 844b3da

Please sign in to comment.