forked from M-Labs/artiq
1
0
Fork 0

worker: make parent errors readable in log.

This commit is contained in:
whitequark 2016-01-16 01:58:45 +00:00
parent 67d2e7a828
commit 6bf48e60ba
2 changed files with 24 additions and 12 deletions

View File

@ -180,9 +180,11 @@ class Worker:
try: try:
data = func(*obj["args"], **obj["kwargs"]) data = func(*obj["args"], **obj["kwargs"])
reply = {"status": "ok", "data": data} reply = {"status": "ok", "data": data}
except: except Exception as e:
reply = {"status": "failed", reply = {"status": "failed",
"message": traceback.format_exc()} "exception": traceback.format_exception_only(type(e), e)[0][:-1],
"message": str(e),
"traceback": traceback.format_tb(e.__traceback__)}
await self.io_lock.acquire() await self.io_lock.acquire()
try: try:
await self._send(reply) await self._send(reply)

View File

@ -2,6 +2,7 @@ import sys
import time import time
import os import os
import logging import logging
import traceback
from collections import OrderedDict from collections import OrderedDict
import artiq import artiq
@ -30,7 +31,7 @@ class ParentActionError(Exception):
pass pass
def make_parent_action(action, exception=ParentActionError): def make_parent_action(action, exception=None):
def parent_action(*args, **kwargs): def parent_action(*args, **kwargs):
request = {"action": action, "args": args, "kwargs": kwargs} request = {"action": action, "args": args, "kwargs": kwargs}
put_object(request) put_object(request)
@ -43,7 +44,12 @@ def make_parent_action(action, exception=ParentActionError):
if reply["status"] == "ok": if reply["status"] == "ok":
return reply["data"] return reply["data"]
else: else:
raise exception(reply["message"]) if exception is None:
exn = ParentActionError(reply["exception"])
else:
exn = exception(reply["message"])
exn.parent_traceback = reply["traceback"]
raise exn
return parent_action return parent_action
@ -172,11 +178,15 @@ def string_to_hdf5(f, key, value):
def setup_diagnostics(experiment_file, repository_path): def setup_diagnostics(experiment_file, repository_path):
def render_diagnostic(self, diagnostic): def render_diagnostic(self, diagnostic):
message = "Cannot compile {}\n".format(experiment_file) + \ message = "While compiling {}\n".format(experiment_file) + \
_render_diagnostic(diagnostic, colored=False) _render_diagnostic(diagnostic, colored=False)
if repository_path is not None: if repository_path is not None:
message = message.replace(repository_path, "<repository>") message = message.replace(repository_path, "<repository>")
logging.error(message)
if diagnostic.level == 'warning':
logging.warn(message)
else:
logging.error(message)
# This is kind of gross, but 1) we do not have any explicit connection # This is kind of gross, but 1) we do not have any explicit connection
# between the worker and a coredevice.core.Core instance at all, # between the worker and a coredevice.core.Core instance at all,
@ -256,12 +266,12 @@ def main():
except CompileError: except CompileError:
pass pass
except Exception as exc: except Exception as exc:
short_exc_info = type(exc).__name__ lines = ["Terminating with exception\n"]
exc_str = str(exc) lines += traceback.format_exception_only(type(exc), exc)
if exc_str: if hasattr(exc, 'parent_traceback'):
short_exc_info += ": " + exc_str lines += exc.parent_traceback
logging.error("Terminating with exception (%s)", logging.error("".join(lines).rstrip(),
short_exc_info, exc_info=True) exc_info=not hasattr(exc, 'parent_traceback'))
finally: finally:
device_mgr.close_devices() device_mgr.close_devices()