diff --git a/afar/_core.py b/afar/_core.py index e552de7..130a952 100644 --- a/afar/_core.py +++ b/afar/_core.py @@ -1,7 +1,6 @@ """Define the user-facing `run` object; this is where it all comes together.""" import dis import sys -import traceback from inspect import currentframe from uuid import uuid4 from weakref import WeakKeyDictionary, WeakSet @@ -345,22 +344,11 @@ def run_afar(magic_func, names, futures, capture_print, channel, unique_key): if magic_func._display_expr and worker is not None: # Hopefully computing the repr is fast. If it is slow, perhaps it would be # better to add the return value to rv and call repr_afar as a separate task. - # Also, pretty_repr must be msgpack serializable if done via events. - # Hence, custom _ipython_display_ probably won't work, and we resort to - # trying to use a basic repr (if that fails, we show the first exception). + # Also, pretty_repr must be msgpack serializable if done via events. Hence, + # custom _ipython_display_ doesn't work, and we resort to using a basic repr. pretty_repr = repr_afar(results.return_value, magic_func._repr_methods) if pretty_repr is not None: - try: - worker.log_event(channel, (unique_key, "display_expr", pretty_repr)) - except Exception: - exc_info = sys.exc_info() - tb = traceback.format_exception(*exc_info) - try: - basic_repr = (repr(results.return_value), "__repr__", False) - worker.log_event(channel, (unique_key, "display_expr", basic_repr)) - except Exception: - exc_repr = (tb, pretty_repr[1], True) - worker.log_event(channel, (unique_key, "display_expr", exc_repr)) + worker.log_event(channel, (unique_key, "display_expr", pretty_repr)) send_finish = False finally: if capture_print and worker is not None and send_finish: diff --git a/afar/_reprs.py b/afar/_reprs.py index a3e8c4a..f3ea60d 100644 --- a/afar/_reprs.py +++ b/afar/_reprs.py @@ -14,7 +14,9 @@ def __init__(self): self._attrs = [] def __getattr__(self, attr): - if "canary" not in attr: + if "canary" not in attr and attr != "_ipython_display_": + # _ipython_display_ requires sending the object back to the client. + # Let's not bother with this hassle for now. self._attrs.append(attr) raise AttributeError(attr) @@ -44,6 +46,7 @@ def repr_afar(val, repr_methods): continue if method_name == "_ipython_display_": # Custom display! Send the object to the client + # We don't allow _ipython_display_ at the moment return val, method_name, False try: rv = method() @@ -100,6 +103,7 @@ def display_repr(results, out=None): from IPython.display import display if method_name == "_ipython_display_": + # We don't allow _ipython_display_ at the moment if out is None: display(val) else: