当前位置: 首页>>代码示例>>Python>>正文


Python inspect.currentframe方法代码示例

本文整理汇总了Python中inspect.currentframe方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.currentframe方法的具体用法?Python inspect.currentframe怎么用?Python inspect.currentframe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inspect的用法示例。


在下文中一共展示了inspect.currentframe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_logger

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def get_logger(filename):
    logging.basicConfig(filename=f"{filename}", filemode='a', format="%(message)s")
    logging.warning(f"[{datetime.datetime.now()}] {'=' * 10}")

    def log(message, error=True):
        func = inspect.currentframe().f_back.f_code
        final_msg = "(%s:%i) %s" % (
            func.co_name,
            func.co_firstlineno,
            message
        )
        if error:
            logging.warning(final_msg)
            print(f"[ERROR] {final_msg}")
        else:
            print(final_msg)

    return log 
开发者ID:harmony-one,项目名称:harmony-ops,代码行数:20,代码来源:utils.py

示例2: __advice_stack_frame_protection

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def __advice_stack_frame_protection(self, frame):
        """
        Overriding of this is only permitted if and only if your name is
        Megumin and you have a pet/familiar named Chomusuke.
        """

        if frame is None:
            logger.debug(
                'currentframe() returned None; frame protection disabled')
            return

        f_back = frame.f_back
        while f_back:
            if f_back.f_code is self.handle.__code__:
                raise RuntimeError(
                    "indirect invocation of '%s' by 'handle' is forbidden" %
                    frame.f_code.co_name,
                )
            f_back = f_back.f_back 
开发者ID:calmjs,项目名称:calmjs,代码行数:21,代码来源:toolchain.py

示例3: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def __init__(self, dialog_state: StatePropertyAccessor = None):
        if dialog_state is None:
            frame = inspect.currentframe().f_back
            try:
                # try to access the caller's "self"
                try:
                    self_obj = frame.f_locals["self"]
                except KeyError:
                    raise TypeError("DialogSet(): dialog_state cannot be None.")
                # Only ComponentDialog can initialize with None dialog_state
                # pylint: disable=import-outside-toplevel
                from .component_dialog import ComponentDialog

                if not isinstance(self_obj, ComponentDialog):
                    raise TypeError("DialogSet(): dialog_state cannot be None.")
            finally:
                # make sure to clean up the frame at the end to avoid ref cycles
                del frame

        self._dialog_state = dialog_state
        # self.__telemetry_client = NullBotTelemetryClient.Instance;

        self._dialogs: Dict[str, object] = {} 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:25,代码来源:dialog_set.py

示例4: execute_only_once

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def execute_only_once():
    """
    Each called in the code to this function is guaranteed to return True the
    first time and False afterwards.

    Returns:
        bool: whether this is the first time this function gets called from this line of code.

    Example:
        .. code-block:: python

            if execute_only_once():
                # do something only once
    """
    f = inspect.currentframe().f_back
    ident = (f.f_code.co_filename, f.f_lineno)
    if ident in _EXECUTE_HISTORY:
        return False
    _EXECUTE_HISTORY.add(ident)
    return True 
开发者ID:tensorpack,项目名称:dataflow,代码行数:22,代码来源:utils.py

示例5: produce

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def produce(self, topic, doc, payload):
    """
    Produce a new event.

    :param topic: The topic of the produced event.
    :param doc: The document to which the event belongs.
    :param payload: The file pointer beloning to the document.
    :type topic: ``str``
    :type doc: ``gransk.core.Document``
    :type payload: ``file``
    """
    caller = inspect.currentframe().f_back.f_locals['self'].__module__
    listeners = self.listeners.get(topic, [])
    filename = os.path.basename(doc.path)

    for listener, callback in listeners:
      LOGGER.debug('[%s] %s -> %s (%s)', topic, caller, listener, filename)
      callback(doc, payload)

    if len(listeners) == 0:
      LOGGER.debug('[%s] %s -> no listeners (%s)', topic, caller, filename) 
开发者ID:pcbje,项目名称:gransk,代码行数:23,代码来源:pipeline.py

示例6: getChannelData_Name

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def getChannelData_Name(self, channel):
        """Get the product name.
        Retrieves the product name of the device connected to channel. The name
        is returned as an ASCII string.
        Args:
            channel (int): The channel you are interested in
        Returns:
            name (string): The product name
        """
        self.fn = inspect.currentframe().f_code.co_name
        name = ct.create_string_buffer(80)
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_DEVDESCR_ASCII,
                                   ct.byref(name), ct.sizeof(name))
        buf_type = ct.c_uint * 1
        buf = buf_type()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CHAN_NO_ON_CARD,
                                   ct.byref(buf), ct.sizeof(buf))
        return "%s (channel %d)" % (name.value, buf[0]) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:22,代码来源:canlib.py

示例7: getChannelData_Chan_No_On_Card

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def getChannelData_Chan_No_On_Card(self, channel):
        """Get the channel number on the card.
        Retrieves the channel number, as numbered locally on the card, device
        connected to channel.
        Args:
            channel (int): The channel you are interested in
        Returns:
            number (int): The local channel number
        """
        self.fn = inspect.currentframe().f_code.co_name
        number = ct.c_ulong()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CHAN_NO_ON_CARD,
                                   ct.byref(number), ct.sizeof(number))
        buf_type = ct.c_uint * 1
        buf = buf_type()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CHAN_NO_ON_CARD,
                                   ct.byref(buf), ct.sizeof(buf))
        return number.value 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:22,代码来源:canlib.py

示例8: getChannelData_CardNumber

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def getChannelData_CardNumber(self, channel):
        """Get the card number
        Retrieves the card's number in the computer. Each card type is numbered
        separately. For example, the first PCIEcan card in a machine will have
        number 0, the second PCIEcan number 1, etc.
        Args:
            channel (int): The channel you are interested in
        Returns:
            card_number (int): The device's card number
        """
        self.fn = inspect.currentframe().f_code.co_name
        buf_type = ct.c_ulong
        buf = buf_type()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CARD_NUMBER,
                                   ct.byref(buf), ct.sizeof(buf))
        return buf.value 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:19,代码来源:canlib.py

示例9: getChannelData_EAN_short

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def getChannelData_EAN_short(self, channel):
        """Get short EAN code
        Retrieves the short EAN number, aka product number, for the device
        connected to channel. If there is no EAN number, "00000-0" will be
        returned.
        Args:
            channel (int): The channel you are interested in
        Returns:
            ean (str): The device's shortened EAN number
        """
        self.fn = inspect.currentframe().f_code.co_name
        buf_type = ct.c_ulong * 2
        buf = buf_type()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CARD_UPC_NO,
                                   ct.byref(buf), ct.sizeof(buf))
        (ean_lo, ean_hi) = struct.unpack('LL', buf)
        return "%04x-%x" % ((ean_lo >> 4) & 0xffff, ean_lo & 0xf) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:20,代码来源:canlib.py

示例10: getChannelData_Serial

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def getChannelData_Serial(self, channel):
        """Get device serial number
        Retrieves the serial number for the device connected to channel. If the
        device does not have a serial number, 0 is returned.
        Args:
            channel (int): The channel you are interested in
        Returns:
            serial (int): The device serial number
        """
        self.fn = inspect.currentframe().f_code.co_name
        buf_type = ct.c_ulong * 2
        buf = buf_type()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CARD_SERIAL_NO,
                                   ct.byref(buf), ct.sizeof(buf))
        (serial_lo, serial_hi) = struct.unpack('LL', buf)
        # serial_hi is always 0
        return serial_lo 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:20,代码来源:canlib.py

示例11: getChannelData_DriverName

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def getChannelData_DriverName(self, channel):
        """Get device driver name
        Retrieves the name of the device driver (e.g. "kcany") for the device
        connected to channel. The device driver names have no special meanings
        and may change from a release to another.
        Args:
            channel (int): The channel you are interested in
        Returns:
            name (str): The device driver name
        """
        self.fn = inspect.currentframe().f_code.co_name
        name = ct.create_string_buffer(80)
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_DRIVER_NAME,
                                   ct.byref(name), ct.sizeof(name))
        return name.value 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:18,代码来源:canlib.py

示例12: getChannelData_Firmware

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def getChannelData_Firmware(self, channel):
        """Get device firmware version
        Retrieves the firmvare version numbers for the device connected to
        channel.
        Args:
            channel (int): The channel you are interested in
        Returns:
            major (int): The major version number
            minor (int): The minor version number
            build (int): The build number
        """
        self.fn = inspect.currentframe().f_code.co_name
        buf_type = ct.c_ushort * 4
        buf = buf_type()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CARD_FIRMWARE_REV,
                                   ct.byref(buf), ct.sizeof(buf))
        (build, release, minor, major) = struct.unpack('HHHH', buf)
        return (major, minor, build) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:21,代码来源:canlib.py

示例13: setBusParamsFd

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def setBusParamsFd(self, freq_brs, tseg1_brs=0, tseg2_brs=0, sjw_brs=0):
        """Set bus timing parameters for BRS in CAN FD
        This function sets the bus timing parameters used in BRS (Bit rate
        switch) mode for the current CANlib channel.
        The library provides default values for tseg1_brs, tseg2_brs and
        sjw_brs when freq is specified to one of the pre-defined constants,
        canFD_BITRATE_xxx.
        If freq is any other value, no default values are supplied by the
        library.
        Args:
            freq_brs: Bitrate in bit/s.
            tseg1_brs: Number of quanta from (but not including) the Sync Segment to
                the sampling point.
            tseg2_brs: Number of quanta from the sampling point to the end of the bit.
            sjw_brs: The Synchronization Jump Width.
        """
        self.canlib.fn = inspect.currentframe().f_code.co_name
        self.dll.canSetBusParamsFd(self.handle, freq_brs, tseg1_brs, tseg2_brs,
                                   sjw_brs) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:21,代码来源:canlib.py

示例14: getChannelData_EAN

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def getChannelData_EAN(self, channel):
        """Get EAN code
        Retrieves the EAN number for the device connected to channel. If there
        is no EAN number, "00-00000-00000-0" will be returned.
        Args:
            channel (int): The channel you are interested in
        Returns:
            ean (str): The device's EAN number
        """
        self.fn = inspect.currentframe().f_code.co_name
        buf_type = ct.c_ulong * 2
        buf = buf_type()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CARD_UPC_NO,
                                   ct.byref(buf), ct.sizeof(buf))
        (ean_lo, ean_hi) = struct.unpack('LL', buf)

        return "%02x-%05x-%05x-%x" % (ean_hi >> 12,
                                      ((ean_hi & 0xfff) << 8) | (ean_lo >> 24),
                                      (ean_lo >> 4) & 0xfffff, ean_lo & 0xf) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:22,代码来源:canlib.py

示例15: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import currentframe [as 别名]
def __init__(self, ignore=None, maxdepth=2, maxparents=10):
        self.ignore = ignore or []
        self.ignore.append(inspect.currentframe().f_back)
        self.maxdepth = maxdepth
        self.maxparents = maxparents 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:7,代码来源:gctools.py


注:本文中的inspect.currentframe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。