當前位置: 首頁>>代碼示例>>Python>>正文


Python inspect.FrameInfo方法代碼示例

本文整理匯總了Python中inspect.FrameInfo方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.FrameInfo方法的具體用法?Python inspect.FrameInfo怎麽用?Python inspect.FrameInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在inspect的用法示例。


在下文中一共展示了inspect.FrameInfo方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_python_file_from_previous_stack_frame

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def get_python_file_from_previous_stack_frame():
    '''inspect.stack() lets us introspect the call stack; inspect.stack()[1] is the previous
    stack frame.

    In Python < 3.5, this is just a tuple, of which the python file of the previous frame is the 1st
    element.

    In Python 3.5+, this is a FrameInfo namedtuple instance; the python file of the previous frame
    remains the 1st element.
    '''

    # Since this is now a function in this file, we need to go back two hops to find the
    # callsite file.
    previous_stack_frame = inspect.stack(0)[2]

    # See: https://docs.python.org/3/library/inspect.html
    if sys.version_info.major == 3 and sys.version_info.minor >= 5:
        check.inst(previous_stack_frame, inspect.FrameInfo)
    else:
        check.inst(previous_stack_frame, tuple)

    python_file = previous_stack_frame[1]
    return os.path.abspath(python_file) 
開發者ID:dagster-io,項目名稱:dagster,代碼行數:25,代碼來源:code_pointer.py

示例2: dump_error

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def dump_error(self, exception: Exception, trace: List[inspect.FrameInfo]) -> None:
        warn_msg = """
>>> PYQUIL_PROTECT <<<
An uncaught exception was raised in a function wrapped in pyquil_protect.  We are writing out a
log file to "{}".

Along with a description of what you were doing when the error occurred, send this file to
Rigetti Computing support by email at support@rigetti.com for assistance.
>>> PYQUIL_PROTECT <<<
""".format(
            os.path.abspath(self.filename)
        )

        _log.warning(warn_msg)

        report = self.generate_report(exception, trace)

        # overwrite any existing log file
        fh = open(self.filename, "w")
        fh.write(json.dumps(report, default=json_serialization_helper))
        fh.close() 
開發者ID:rigetti,項目名稱:pyquil,代碼行數:23,代碼來源:_error_reporting.py

示例3: _get_trace

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def _get_trace(_self: _Failure) -> Optional[List[FrameInfo]]:
    """
    Function to be used on Monkey Patching.

    This function is the substitute for '_get_trace' method from ``_Failure``
    class on Monkey Patching promoted by
    :func:`returns.primitives.tracing.collect_traces` function.

    We get all the call stack from the current call and return it from the
    third position, to avoid two non-useful calls on the call stack.
    Those non-useful calls are a call to this function and a call to `__init__`
    method from ``_Failure`` class. We're just interested in the call stack
    ending on ``Failure`` function call!

    See also:
        https://github.com/dry-python/returns/issues/409

    """
    current_stack = stack()
    return current_stack[2:] 
開發者ID:dry-python,項目名稱:returns,代碼行數:22,代碼來源:tracing.py

示例4: real_frame_extract

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def real_frame_extract(subframe, filepath, lineno):
    """
    :type subframe: inspect.FrameInfo
    :rtype: inspect.FrameInfo
    """
    frames = inspect.getouterframes(subframe)
    for frame in frames:
        if PY2:
            if frame[1] == filepath and frame[2] == lineno:
                return frame[0]  # type: inspect.FrameInfo
        elif frame.filename == filepath and frame.lineno == lineno:
            return frame.frame  # type: inspect.FrameInfo
    
    return None 
開發者ID:neargle,項目名稱:ver-observer,代碼行數:16,代碼來源:frame_operations.py

示例5: generate_report

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def generate_report(self, exception: Exception, trace: List[inspect.FrameInfo]) -> ErrorReport:
        """
        Handle an error generated in a routine decorated with the pyQuil error handler.

        :param exception: Exception object that generated this error.
        :param trace: inspect.trace object from the frame that caught the error.
        :return: ErrorReport object
        """
        stack_trace = [
            StacktraceFrame(
                name=item.function,
                filename=item.filename,
                line_number=item.lineno,
                locals={
                    k: serialize_object_for_logging(v) for (k, v) in item.frame.f_locals.items()
                },
            )
            for item in trace
        ]

        system_info = generate_system_info()

        report = ErrorReport(
            stack_trace=stack_trace,
            timestamp=datetime.utcnow(),
            exception=exception,
            system_info=system_info,
            call_log=flatten_log(self.log),
        )

        return report 
開發者ID:rigetti,項目名稱:pyquil,代碼行數:33,代碼來源:_error_reporting.py

示例6: trace

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def trace(self) -> Optional[List[FrameInfo]]:
        """Returns a list with stack trace when :func:`~Failure` was called."""
        return self._trace 
開發者ID:dry-python,項目名稱:returns,代碼行數:5,代碼來源:result.py

示例7: _get_trace

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def _get_trace(self) -> Optional[List[FrameInfo]]:
        """Method that will be monkey patched when trace is active."""
        return None  # noqa: WPS324 
開發者ID:dry-python,項目名稱:returns,代碼行數:5,代碼來源:result.py

示例8: trace

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def trace(self) -> Optional[List[FrameInfo]]:
        """Returns a list with stack trace when :func:`~Failure` was called."""
        return self._inner_value.trace 
開發者ID:dry-python,項目名稱:returns,代碼行數:5,代碼來源:io.py

示例9: collect_traces

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def collect_traces(
    function: Optional[_FunctionType] = None,
) -> Union[_FunctionType, ContextManager[None]]:  # noqa: DAR101, DAR201, DAR301
    """
    Context Manager/Decorator to active traces collect to the Failures.

    .. code:: python

        >>> from inspect import FrameInfo

        >>> from returns.io import IOResult
        >>> from returns.result import Result
        >>> from returns.primitives.tracing import collect_traces

        >>> with collect_traces():
        ...     traced_failure = Result.from_failure('Traced Failure')
        >>> non_traced_failure = IOResult.from_failure('Non Traced Failure')

        >>> assert non_traced_failure.trace is None
        >>> assert isinstance(traced_failure.trace, list)
        >>> assert all(isinstance(trace_line, FrameInfo) for trace_line in traced_failure.trace)

        >>> for trace_line in traced_failure.trace:
        ...     print(f'{trace_line.filename}:{trace_line.lineno} in `{trace_line.function}`') # doctest: +SKIP
        ...
        /returns/returns/result.py:525 in `Failure`
        /returns/returns/result.py:322 in `from_failure`
        /example_folder/example.py:1 in `<module>`
        # doctest: # noqa: DAR301, E501

    """
    @contextmanager
    def factory() -> Iterator[None]:
        unpatched_get_trace = getattr(_Failure, '_get_trace')  # noqa: B009
        substitute_get_trace = types.MethodType(_get_trace, _Failure)
        setattr(_Failure, '_get_trace', substitute_get_trace)  # noqa: B010
        try:  # noqa: WPS501
            yield
        finally:
            setattr(_Failure, '_get_trace', unpatched_get_trace)  # noqa: B010
    return factory()(function) if function else factory() 
開發者ID:dry-python,項目名稱:returns,代碼行數:43,代碼來源:tracing.py

示例10: _set_filename

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FrameInfo [as 別名]
def _set_filename(self, filename):
        """Mock the NApp's main.py file path."""
        # Put the filename in the call stack
        frame = FrameInfo(None, filename, None, None, None, None)
        self._inspect_patcher = patch('kytos.core.logs.inspect')
        inspect = self._inspect_patcher.start()
        inspect.stack.return_value = [frame] 
開發者ID:kytos,項目名稱:kytos,代碼行數:9,代碼來源:test_logs.py


注:本文中的inspect.FrameInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。