def test_sync_error(loop_in_thread): loop = loop_in_thread try: result = sync(loop, throws, 1) except Exception as exc: f = exc assert 'hello' in str(exc) tb = get_traceback() L = traceback.format_tb(tb) assert any('throws' in line for line in L) def function1(x): return function2(x) def function2(x): return throws(x) try: result = sync(loop, function1, 1) except Exception as exc: assert 'hello' in str(exc) tb = get_traceback() L = traceback.format_tb(tb) assert any('function1' in line for line in L) assert any('function2' in line for line in L)
def test_sync_error(loop_in_thread): loop = loop_in_thread try: result = sync(loop, throws, 1) except Exception as exc: f = exc assert "hello" in str(exc) tb = get_traceback() L = traceback.format_tb(tb) assert any("throws" in line for line in L) def function1(x): return function2(x) def function2(x): return throws(x) try: result = sync(loop, function1, 1) except Exception as exc: assert "hello" in str(exc) tb = get_traceback() L = traceback.format_tb(tb) assert any("function1" in line for line in L) assert any("function2" in line for line in L)
def test_sync_error(loop): e = Event() @gen.coroutine def wait_until_event(): yield e.wait() thread = Thread(target=loop.run_sync, args=(wait_until_event, )) thread.daemon = True thread.start() while not loop._running: sleep(0.01) try: result = sync(loop, throws, 1) except Exception as exc: f = exc assert 'hello' in str(exc) tb = get_traceback() L = traceback.format_tb(tb) assert any('throws' in line for line in L) def function1(x): return function2(x) def function2(x): return throws(x) try: result = sync(loop, function1, 1) except Exception as exc: assert 'hello' in str(exc) tb = get_traceback() L = traceback.format_tb(tb) assert any('function1' in line for line in L) assert any('function2' in line for line in L) loop.add_callback(e.set) thread.join()
def test_sync_error(loop): e = Event() @gen.coroutine def wait_until_event(): yield e.wait() thread = Thread(target=loop.run_sync, args=(wait_until_event,)) thread.daemon = True thread.start() while not loop._running: sleep(0.01) try: result = sync(loop, throws, 1) except Exception as exc: f = exc assert 'hello' in str(exc) tb = get_traceback() L = traceback.format_tb(tb) assert any('throws' in line for line in L) def function1(x): return function2(x) def function2(x): return throws(x) try: result = sync(loop, function1, 1) except Exception as exc: assert 'hello' in str(exc) tb = get_traceback() L = traceback.format_tb(tb) assert any('function1' in line for line in L) assert any('function2' in line for line in L) loop.add_callback(e.set) thread.join()
def test_get_traceback(): def a(x): return div(x, 0) def b(x): return a(x) def c(x): return b(x) try: c(x) except Exception as e: tb = get_traceback() assert type(tb).__name__ == 'traceback'
def test_get_traceback(): def a(x): return div(x, 0) def b(x): return a(x) def c(x): return b(x) try: c(1) except Exception as e: tb = get_traceback() assert type(tb).__name__ == "traceback"
def error_message(e, status="error"): """Produce message to send back given an exception has occurred This does the following: 1. Gets the traceback 2. Truncates the exception and the traceback 3. Serializes the exception and traceback or 4. If they can't be serialized send string versions 5. Format a message and return See Also -------- clean_exception : deserialize and unpack message into exception/traceback """ MAX_ERROR_LEN = dask.config.get("distributed.admin.max-error-length") tblib.pickling_support.install(e, *collect_causes(e)) tb = get_traceback() tb_text = "".join(traceback.format_tb(tb)) e = truncate_exception(e, MAX_ERROR_LEN) try: e_serialized = protocol.pickle.dumps(e) protocol.pickle.loads(e_serialized) except Exception: e_serialized = protocol.pickle.dumps(Exception(repr(e))) e_serialized = protocol.to_serialize(e_serialized) try: tb_serialized = protocol.pickle.dumps(tb) protocol.pickle.loads(tb_serialized) except Exception: tb_serialized = protocol.pickle.dumps(tb_text) if len(tb_serialized) > MAX_ERROR_LEN: tb_result = None else: tb_result = protocol.to_serialize(tb_serialized) return { "status": status, "exception": e_serialized, "traceback": tb_result, "exception_text": repr(e), "traceback_text": tb_text, }