Skip to content

Commit fa48c65

Browse files
fixups ball of mud
1 parent 7e86f6e commit fa48c65

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/execnet/gateway_base.py

+13-8
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:
@@ -277,6 +277,8 @@ class Reply:
277277
through WorkerPool.spawn()
278278
"""
279279

280+
_exception: BaseException | None = None
281+
280282
def __init__(self, task, threadmodel):
281283
self.task = task
282284
self._result_ready = threadmodel.Event()
@@ -289,10 +291,10 @@ def get(self, timeout=None):
289291
including its traceback.
290292
"""
291293
self.waitfinish(timeout)
292-
try:
294+
if self._exception is None:
293295
return self._result
294-
except AttributeError:
295-
raise self._exc
296+
else:
297+
raise self._exception.with_traceback(self._exception.__traceback__)
296298

297299
def waitfinish(self, timeout=None):
298300
if not self._result_ready.wait(timeout):
@@ -303,8 +305,9 @@ def run(self):
303305
try:
304306
try:
305307
self._result = func(*args, **kwargs)
306-
except BaseException as exc:
307-
self._exc = exc
308+
except BaseException as e:
309+
# sys may be already None when shutting down the interpreter
310+
self._exception = e
308311
finally:
309312
self._result_ready.set()
310313
self.running = False
@@ -486,7 +489,9 @@ def __init__(self, outfile, infile, execmodel):
486489
except (AttributeError, OSError):
487490
pass
488491
self._read = getattr(infile, "buffer", infile).read
489-
self._write = getattr(outfile, "buffer", outfile).write
492+
_outfile = getattr(outfile, "buffer", outfile)
493+
self._write = _outfile.write
494+
self._flush = _outfile.flush
490495
self.execmodel = execmodel
491496

492497
def read(self, numbytes):
@@ -504,7 +509,7 @@ def write(self, data):
504509
"""write out all data bytes."""
505510
assert isinstance(data, bytes)
506511
self._write(data)
507-
self.outfile.flush()
512+
self._flush()
508513

509514
def close_read(self):
510515
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)