Skip to content

Commit cb6f3e1

Browse files
fixups ball of mud
1 parent 7e00812 commit cb6f3e1

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ html = "sphinx-build -W -b html doc doc/_build"
8080

8181
[tool.hatch.envs.pre-commit]
8282
detached = true
83-
dependences = ["pre-commit>1.11.0"]
83+
dependences = ["pre-commit>=2.20.0"]
8484

8585
[tool.hatch.envs.pre-commit.scripts]
8686
all = "pre-commit run --all-files --show-diff-on-failure"

src/execnet/gateway_base.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
base execnet gateway code send to the other side for bootstrapping.
33
4-
NOTE: aims to be compatible to Python 2.5-3.X, Jython and IronPython
4+
NOTE: aims to be compatible to Python 3.8+
55
66
:copyright: 2004-2015
77
:authors:
@@ -153,6 +153,8 @@ class Reply:
153153
through WorkerPool.spawn()
154154
"""
155155

156+
_exception: BaseException | None = None
157+
156158
def __init__(self, task, threadmodel):
157159
self.task = task
158160
self._result_ready = threadmodel.Event()
@@ -165,10 +167,10 @@ def get(self, timeout=None):
165167
including its traceback.
166168
"""
167169
self.waitfinish(timeout)
168-
try:
170+
if self._exception is None:
169171
return self._result
170-
except AttributeError:
171-
reraise(*(self._excinfo[:3])) # noqa
172+
else:
173+
raise self._exception.with_traceback(self._exception.__traceback__)
172174

173175
def waitfinish(self, timeout=None):
174176
if not self._result_ready.wait(timeout):
@@ -179,10 +181,9 @@ def run(self):
179181
try:
180182
try:
181183
self._result = func(*args, **kwargs)
182-
except:
184+
except BaseException as e:
183185
# sys may be already None when shutting down the interpreter
184-
if sys is not None:
185-
self._excinfo = sys.exc_info()
186+
self._exception = e
186187
finally:
187188
self._result_ready.set()
188189
self.running = False
@@ -348,7 +349,9 @@ def __init__(self, outfile, infile, execmodel):
348349
except (AttributeError, OSError):
349350
pass
350351
self._read = getattr(infile, "buffer", infile).read
351-
self._write = getattr(outfile, "buffer", outfile).write
352+
_outfile = getattr(outfile, "buffer", outfile)
353+
self._write = _outfile.write
354+
self._flush = _outfile.flush
352355
self.execmodel = execmodel
353356

354357
def read(self, numbytes):
@@ -366,7 +369,7 @@ def write(self, data):
366369
"""write out all data bytes."""
367370
assert isinstance(data, bytes)
368371
self._write(data)
369-
self.outfile.flush()
372+
self._flush()
370373

371374
def close_read(self):
372375
self.infile.close()

testing/test_xspec.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import execnet
99
import pytest
1010
from execnet.gateway_io import popen_args
11+
from execnet.gateway_io import popen_bootstrapline
1112
from execnet.gateway_io import ssh_args
1213
from execnet.gateway_io import vagrant_ssh_args
1314

@@ -77,13 +78,7 @@ def test_vagrant_options(self):
7778

7879
def test_popen_with_sudo_python(self):
7980
spec = XSpec("popen//python=sudo python3")
80-
assert popen_args(spec) == [
81-
"sudo",
82-
"python3",
83-
"-u",
84-
"-c",
85-
"import sys;exec(eval(sys.stdin.readline()))",
86-
]
81+
assert popen_args(spec) == ["sudo", "python3", "-u", "-c", popen_bootstrapline]
8782

8883
def test_env(self):
8984
xspec = XSpec("popen//env:NAME=value1")

0 commit comments

Comments
 (0)