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 Feb 24, 2024
1 parent 7e86f6e commit fa48c65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
21 changes: 13 additions & 8 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 @@ -277,6 +277,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 @@ -289,10 +291,10 @@ def get(self, timeout=None):
including its traceback.
"""
self.waitfinish(timeout)
try:
if self._exception is None:
return self._result
except AttributeError:
raise self._exc
else:
raise self._exception.with_traceback(self._exception.__traceback__)

def waitfinish(self, timeout=None):
if not self._result_ready.wait(timeout):
Expand All @@ -303,8 +305,9 @@ def run(self):
try:
try:
self._result = func(*args, **kwargs)
except BaseException as exc:
self._exc = exc
except BaseException as e:
# sys may be already None when shutting down the interpreter
self._exception = e
finally:
self._result_ready.set()
self.running = False
Expand Down Expand Up @@ -486,7 +489,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 @@ -504,7 +509,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 fa48c65

Please sign in to comment.