async def worker(cls, cls_args, sockname): con = await amsg.worker_connect(sockname) worker = cls(*cls_args) while True: req = await con.next_request() try: methname, args = pickle.loads(req) except Exception as ex: data = (1, ex, traceback.format_exc()) else: meth = getattr(worker, methname) try: res = await meth(*args) data = (0, res) except Exception as ex: if debug.flags.server: markup.dump(ex, marker="exception in methname()", file=sys.stderr) ex_str = str(ex) data = (1, ex, traceback.format_exc()) try: pickled = pickle.dumps(data) except Exception as ex: ex_tb = traceback.format_exc() ex_str = f'{ex}:\n\n{ex_tb}' pickled = pickle.dumps((2, ex_str)) await con.reply(pickled)
def run_test(self, *, source, spec=None, expected=None): debug = bool(os.environ.get(self.parser_debug_flag)) if debug: markup.dump_code(source, lexer=self.markup_dump_lexer) p = self.get_parser(spec=spec) inast = p.parse(source) if debug: markup.dump(inast) for var in inast.definitions[0].variables: asttype, val = expected[var.name] self.assertIsInstance(var.value, asttype) self.assertEqual(var.value.value, val)
def run_test(self, *, source, spec, expected=None): debug = bool(os.environ.get(self.parser_debug_flag)) if debug: markup.dump_code(source, lexer=self.markup_dump_lexer) p = self.get_parser(spec=spec) inast = p.parse(source) if debug: markup.dump(inast) # make sure that the AST has context # context.ContextValidator().visit(inast) processed_src = self.ast_to_source(inast) if debug: markup.dump_code(processed_src, lexer=self.markup_dump_lexer) expected_src = source if expected is None else expected self.assert_equal(expected_src, processed_src)
def excepthook(exctype, exc, tb): try: from edb.lang.common import markup markup.dump(exc, file=sys.stderr) except Exception as ex: print('!!! exception in edb.excepthook !!!', file=sys.stderr) # Attach the original exception as a context to top of the new chain, # but only if it's not already there. Take some care to avoid looping # forever. visited = set() parent = ex while parent.__cause__ or (not parent.__suppress_context__ and parent.__context__): if (parent in visited or parent.__context__ is exc or parent.__cause__ is exc): break visited.add(parent) parent = parent.__cause__ or parent.__context__ parent.__context__ = exc parent.__cause__ = None _old_excepthook(type(ex), ex, ex.__traceback__)
def dump(self): markup.dump(self)