Ejemplo n.º 1
0
    def exit_call(self, exit_info):
        # type: (ExitCallInfo) -> None
        """
        This is where all the data collected during the call is gathered up
        and sent to the database.
        """
        frame = exit_info.current_frame  # type: FrameType
        if frame.f_code not in self._code_infos or _tracing_recursively(frame):
            return
        frame_info = self.stack[frame]

        top_iteration = frame_info.iteration  # type: Iteration
        node_values = _deep_dict()
        self._extract_node_values(top_iteration, (), node_values)

        db_func = self._code_infos[frame.f_code].db_func
        exc = exit_info.exc_value  # type: Optional[Exception]
        if exc:
            traceback_str = "".join(
                traceback.format_exception(type(exc), exc, exit_info.exc_tb)
            )
            exception = exception_string(exc)
        else:
            traceback_str = exception = None

        @retry_db
        def add_call():
            Call = self.db.Call
            job_id = self._db_job(self.job_name)
            # job = Job
            call = Call(
                id=frame_info.call_id,
                function_id=db_func,
                arguments=frame_info.arguments,
                return_value=cheap_repr(exit_info.return_value),
                exception=exception,
                traceback=traceback_str,
                data=json.dumps(
                    dict(
                        node_values=node_values,
                        loop_iterations=top_iteration.extract_iterations()["loops"],
                        type_names=type_registry.names(),
                        num_special_types=type_registry.num_special_types,
                    ),
                    cls=ProtocolEncoder,
                    separators=(",", ":"),
                ),
                start_time=frame_info.start_time,
                job_id=job_id,
            )
            with self.db.session_scope() as session:
                session.add(call)

        add_call()

        self._last_call_id = frame_info.call_id
Ejemplo n.º 2
0
    def exit_call(self, exit_info):
        # type: (ExitCallInfo) -> None
        """
        This is where all the data collected during the call is gathered up
        and sent to the database.
        """
        frame = exit_info.current_frame  # type: FrameType
        if frame.f_code not in self._code_infos or _tracing_recursively(frame):
            return
        frame_info = self.stack[frame]

        top_iteration = frame_info.iteration  # type: Iteration
        node_values = _deep_dict()
        self._extract_node_values(top_iteration, (), node_values)

        db_func = self._code_infos[frame.f_code].db_func
        exc = exit_info.exc_value  # type: Optional[Exception]
        if exc:
            traceback_str = ''.join(traceback.format_exception(type(exc), exc, exit_info.exc_tb))
            exception = exception_string(exc)
        else:
            traceback_str = exception = None

        Call = self.db.Call
        session = self.db.session

        call = Call(id=frame_info.call_id,
                    function=db_func,
                    arguments=frame_info.arguments,
                    return_value=cheap_repr(exit_info.return_value),
                    exception=exception,
                    traceback=traceback_str,
                    data=json.dumps(
                        dict(
                            node_values=node_values,
                            loop_iterations=top_iteration.extract_iterations()['loops'],
                            type_names=type_registry.names(),
                            num_special_types=type_registry.num_special_types,
                        ),
                        cls=ProtocolEncoder,
                        separators=(',', ':')
                    ),
                    start_time=frame_info.start_time)
        session.add(call)
        session.commit()
        if self._ipython_cell_call_id is not None:
            self._ipython_cell_call_id = frame_info.call_id
Ejemplo n.º 3
0
def _try_repr(func, x, *args):
    try:
        return func(x, *args)
    except BaseException as e:
        should_raise = (cheap_repr.raise_exceptions or
                        getattr(func, 'raise_exceptions', False) or
                        func is repr and __raise_exceptions_from_default_repr)
        if should_raise:
            raise
        cls = x.__class__
        if cls not in suppressed_classes:
            suppressed_classes.add(cls)
            warnings.warn(ReprSuppressedWarning(
                "Exception '%s' in %s for object of type %s. "
                "The repr has been suppressed for this type." %
                (exception_string(e), func.__name__, safe_qualname(cls))))
        return _basic_but('exception in repr', x)
Ejemplo n.º 4
0
 def exception(cls, exc_value):
     """
     Means that exc_value was raised by a node when executing, and not any inner node.
     """
     return cls(exception_string(exc_value), -1)