Skip to content

Commit 08bb48f

Browse files
fixups ball of mud
1 parent 42245d3 commit 08bb48f

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/execnet/gateway_base.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ class Reply:
316316
"""Provide access to the result of a function execution that got dispatched
317317
through WorkerPool.spawn()."""
318318

319+
_exception: BaseException | None = None
320+
319321
def __init__(self, task, threadmodel: ExecModel) -> None:
320322
self.task = task
321323
self._result_ready = threadmodel.Event()
@@ -328,10 +330,10 @@ def get(self, timeout: float | None = None):
328330
including its traceback.
329331
"""
330332
self.waitfinish(timeout)
331-
try:
333+
if self._exception is None:
332334
return self._result
333-
except AttributeError:
334-
raise self._exc from None
335+
else:
336+
raise self._exception.with_traceback(self._exception.__traceback__)
335337

336338
def waitfinish(self, timeout: float | None = None) -> None:
337339
if not self._result_ready.wait(timeout):
@@ -342,8 +344,9 @@ def run(self) -> None:
342344
try:
343345
try:
344346
self._result = func(*args, **kwargs)
345-
except BaseException as exc:
346-
self._exc = exc
347+
except BaseException as e:
348+
# sys may be already None when shutting down the interpreter
349+
self._exception = e
347350
finally:
348351
self._result_ready.set()
349352
self.running = False
@@ -526,7 +529,9 @@ def __init__(self, outfile, infile, execmodel: ExecModel) -> None:
526529
except (AttributeError, OSError):
527530
pass
528531
self._read = getattr(infile, "buffer", infile).read
529-
self._write = getattr(outfile, "buffer", outfile).write
532+
_outfile = getattr(outfile, "buffer", outfile)
533+
self._write = _outfile.write
534+
self._flush = _outfile.flush
530535
self.execmodel = execmodel
531536

532537
def read(self, numbytes: int) -> bytes:
@@ -544,7 +549,7 @@ def write(self, data: bytes) -> None:
544549
"""Write out all data bytes."""
545550
assert isinstance(data, bytes)
546551
self._write(data)
547-
self.outfile.flush()
552+
self._flush()
548553

549554
def close_read(self) -> None:
550555
self.infile.close()

testing/test_xspec.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from execnet import XSpec
1313
from execnet.gateway import Gateway
1414
from execnet.gateway_io import popen_args
15+
from execnet.gateway_io import popen_bootstrapline
1516
from execnet.gateway_io import ssh_args
1617
from execnet.gateway_io import vagrant_ssh_args
1718

@@ -78,13 +79,7 @@ def test_vagrant_options(self) -> None:
7879

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

8984
def test_env(self) -> None:
9085
xspec = XSpec("popen//env:NAME=value1")

0 commit comments

Comments
 (0)