Skip to content

Commit

Permalink
fixups ball of mud
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Jan 17, 2023
1 parent 7e00812 commit cb6f3e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ html = "sphinx-build -W -b html doc doc/_build"

[tool.hatch.envs.pre-commit]
detached = true
dependences = ["pre-commit>1.11.0"]
dependences = ["pre-commit>=2.20.0"]

[tool.hatch.envs.pre-commit.scripts]
all = "pre-commit run --all-files --show-diff-on-failure"
Expand Down
21 changes: 12 additions & 9 deletions src/execnet/gateway_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
base execnet gateway code send to the other side for bootstrapping.
NOTE: aims to be compatible to Python 2.5-3.X, Jython and IronPython
NOTE: aims to be compatible to Python 3.8+
:copyright: 2004-2015
:authors:
Expand Down Expand Up @@ -153,6 +153,8 @@ class Reply:
through WorkerPool.spawn()
"""

_exception: BaseException | None = None

def __init__(self, task, threadmodel):
self.task = task
self._result_ready = threadmodel.Event()
Expand All @@ -165,10 +167,10 @@ def get(self, timeout=None):
including its traceback.
"""
self.waitfinish(timeout)
try:
if self._exception is None:
return self._result
except AttributeError:
reraise(*(self._excinfo[:3])) # noqa
else:
raise self._exception.with_traceback(self._exception.__traceback__)

def waitfinish(self, timeout=None):
if not self._result_ready.wait(timeout):
Expand All @@ -179,10 +181,9 @@ def run(self):
try:
try:
self._result = func(*args, **kwargs)
except:
except BaseException as e:
# sys may be already None when shutting down the interpreter
if sys is not None:
self._excinfo = sys.exc_info()
self._exception = e
finally:
self._result_ready.set()
self.running = False
Expand Down Expand Up @@ -348,7 +349,9 @@ def __init__(self, outfile, infile, execmodel):
except (AttributeError, OSError):
pass
self._read = getattr(infile, "buffer", infile).read
self._write = getattr(outfile, "buffer", outfile).write
_outfile = getattr(outfile, "buffer", outfile)
self._write = _outfile.write
self._flush = _outfile.flush
self.execmodel = execmodel

def read(self, numbytes):
Expand All @@ -366,7 +369,7 @@ def write(self, data):
"""write out all data bytes."""
assert isinstance(data, bytes)
self._write(data)
self.outfile.flush()
self._flush()

def close_read(self):
self.infile.close()
Expand Down
9 changes: 2 additions & 7 deletions testing/test_xspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import execnet
import pytest
from execnet.gateway_io import popen_args
from execnet.gateway_io import popen_bootstrapline
from execnet.gateway_io import ssh_args
from execnet.gateway_io import vagrant_ssh_args

Expand Down Expand Up @@ -77,13 +78,7 @@ def test_vagrant_options(self):

def test_popen_with_sudo_python(self):
spec = XSpec("popen//python=sudo python3")
assert popen_args(spec) == [
"sudo",
"python3",
"-u",
"-c",
"import sys;exec(eval(sys.stdin.readline()))",
]
assert popen_args(spec) == ["sudo", "python3", "-u", "-c", popen_bootstrapline]

def test_env(self):
xspec = XSpec("popen//env:NAME=value1")
Expand Down

0 comments on commit cb6f3e1

Please sign in to comment.