From 774238955801499a4ed875024827ddc40ea8c062 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 30 Oct 2024 11:18:07 +0100 Subject: [PATCH 1/2] include traceback in wrong error in raises_remote for easier debugging --- ipyparallel/tests/clienttest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ipyparallel/tests/clienttest.py b/ipyparallel/tests/clienttest.py index 7f604822..f0976e62 100644 --- a/ipyparallel/tests/clienttest.py +++ b/ipyparallel/tests/clienttest.py @@ -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") From 59b5a3fa94516787cdc93d25eb165415711194f7 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 30 Oct 2024 11:42:36 +0100 Subject: [PATCH 2/2] safer pop from working namespace log failure as a warning because it's weird, but not impossible --- ipyparallel/engine/kernel.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ipyparallel/engine/kernel.py b/ipyparallel/engine/kernel.py index efc8b0b2..8c900167 100644 --- a/ipyparallel/engine/kernel.py +++ b/ipyparallel/engine/kernel.py @@ -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" @@ -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,