Skip to content

Commit 91e1100

Browse files
authored
Merge pull request #907 from minrk/raises-remote
include traceback in wrong error in raises_remote
2 parents 204d777 + 59b5a3f commit 91e1100

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

ipyparallel/engine/kernel.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,10 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
139139
try:
140140
working = shell.user_ns
141141

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

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

146-
fname = getattr(f, '__name__', 'f')
147-
148146
fname = prefix + "f"
149147
argname = prefix + "args"
150148
kwargname = prefix + "kwargs"
@@ -153,13 +151,18 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
153151
ns = {fname: f, argname: args, kwargname: kwargs, resultname: None}
154152
# print ns
155153
working.update(ns)
156-
code = f"{resultname} = {fname}(*{argname},**{kwargname})"
154+
code = f"{resultname} = {fname}(*{argname}, **{kwargname})"
157155
try:
158156
exec(code, shell.user_global_ns, shell.user_ns)
159157
result = working.get(resultname)
160158
finally:
161159
for key in ns:
162-
working.pop(key)
160+
try:
161+
working.pop(key)
162+
except KeyError:
163+
self.log.warning(
164+
f"Failed to undefine temporary apply variable {key}, already undefined"
165+
)
163166

164167
result_buf = serialize_object(
165168
result,

ipyparallel/tests/clienttest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ def raises_remote(etype):
106106
except error.CompositeError as e:
107107
e.raise_exception()
108108
except error.RemoteError as e:
109+
tb = '\n'.join(e.render_traceback())
109110
assert (
110111
expected_ename == e.ename
111-
), f"Should have raised {expected_ename}, but raised {e.ename}"
112+
), f"Should have raised {expected_ename}, but raised {e.ename}:\n{tb}"
112113

113114
else:
114115
pytest.fail("should have raised a RemoteError")

0 commit comments

Comments
 (0)