Skip to content

Commit

Permalink
Merge pull request #907 from minrk/raises-remote
Browse files Browse the repository at this point in the history
include traceback in wrong error in raises_remote
  • Loading branch information
minrk authored Oct 30, 2024
2 parents 204d777 + 59b5a3f commit 91e1100
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions ipyparallel/engine/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
try:
working = shell.user_ns

prefix = "_" + str(msg_id).replace("-", "") + "_"
prefix = f"_{str(msg_id).replace('-', '_')}_"

f, args, kwargs = unpack_apply_message(bufs, working, copy=False)

fname = getattr(f, '__name__', 'f')

fname = prefix + "f"
argname = prefix + "args"
kwargname = prefix + "kwargs"
Expand All @@ -153,13 +151,18 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
ns = {fname: f, argname: args, kwargname: kwargs, resultname: None}
# print ns
working.update(ns)
code = f"{resultname} = {fname}(*{argname},**{kwargname})"
code = f"{resultname} = {fname}(*{argname}, **{kwargname})"
try:
exec(code, shell.user_global_ns, shell.user_ns)
result = working.get(resultname)
finally:
for key in ns:
working.pop(key)
try:
working.pop(key)
except KeyError:
self.log.warning(
f"Failed to undefine temporary apply variable {key}, already undefined"
)

result_buf = serialize_object(
result,
Expand Down
3 changes: 2 additions & 1 deletion ipyparallel/tests/clienttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ def raises_remote(etype):
except error.CompositeError as e:
e.raise_exception()
except error.RemoteError as e:
tb = '\n'.join(e.render_traceback())
assert (
expected_ename == e.ename
), f"Should have raised {expected_ename}, but raised {e.ename}"
), f"Should have raised {expected_ename}, but raised {e.ename}:\n{tb}"

else:
pytest.fail("should have raised a RemoteError")
Expand Down

0 comments on commit 91e1100

Please sign in to comment.