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


Python patcher.is_monkey_patched方法代码示例

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


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

示例1: run

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def run(self, handler):
        from eventlet import wsgi, listen, patcher
        if not patcher.is_monkey_patched(os):
            msg = "Bottle requires eventlet.monkey_patch() (before import)"
            raise RuntimeError(msg)
        socket_args = {}
        for arg in ('backlog', 'family'):
            try:
                socket_args[arg] = self.options.pop(arg)
            except KeyError:
                pass
        address = (self.host, self.port)
        try:
            wsgi.server(listen(address, **socket_args), handler,
                        log_output=(not self.quiet))
        except TypeError:
            # Fallback, if we have old version of eventlet
            wsgi.server(listen(address), handler) 
开发者ID:brycesub,项目名称:silvia-pi,代码行数:20,代码来源:bottle.py

示例2: threading_local_monkey_patched

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def threading_local_monkey_patched():
    # Returns True if thread locals have been patched by either gevent of
    # eventlet
    try:
        from gevent.monkey import is_object_patched
    except ImportError:
        pass
    else:
        if is_object_patched("threading", "local"):
            return True

    try:
        from eventlet.patcher import is_monkey_patched
    except ImportError:
        pass
    else:
        if is_monkey_patched("thread"):
            return True

    return False 
开发者ID:elastic,项目名称:apm-agent-python,代码行数:22,代码来源:__init__.py

示例3: check_evenlet_monkey_patch

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def check_evenlet_monkey_patch(raise_exc=True):
    if not patcher.is_monkey_patched('socket'):  # 随便选一个检测标志
        if raise_exc:
            warnings.warn(f'检测到没有打 evenlet 包的猴子补丁 ,请在起始脚本文件首行加上     import eventlet;eventlet.monkey_patch(all=True) ')
            raise Exception('检测到没有打 evenlet 包的猴子补丁 ,请在起始脚本文件首行加上    import eventlet;eventlet.monkey_patch(all=True)')
    else:
        return 1 
开发者ID:ydf0509,项目名称:distributed_framework,代码行数:9,代码来源:custom_evenlet_pool_executor.py

示例4: test_eventlet_thread_monkeypatched

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def test_eventlet_thread_monkeypatched():
    eventlet.monkey_patch(thread=True)
    assert is_monkey_patched("thread")

    execution_context = elasticapm.context.init_execution_context()

    # Should always use ThreadLocalContext when eventlet has patched
    # threading.local
    assert isinstance(execution_context, ThreadLocalContext) 
开发者ID:elastic,项目名称:apm-agent-python,代码行数:11,代码来源:eventlet_threading_tests.py

示例5: test_transaction_with_eventlet

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def test_transaction_with_eventlet(sending_elasticapm_client):
    assert is_monkey_patched(os)
    transaction = sending_elasticapm_client.begin_transaction("test")
    with elasticapm.capture_span("bla"):
        pass
    sending_elasticapm_client.end_transaction("test", "OK")
    sending_elasticapm_client.close()
    assert len(sending_elasticapm_client.httpserver.requests) == 1
    assert sending_elasticapm_client.httpserver.payloads[0][1][constants.SPAN]
    assert sending_elasticapm_client.httpserver.payloads[0][2][constants.TRANSACTION] 
开发者ID:elastic,项目名称:apm-agent-python,代码行数:12,代码来源:test_eventlet.py

示例6: initialize

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def initialize(self):
        super(KombuManager, self).initialize()

        monkey_patched = True
        if self.server.async_mode == 'eventlet':
            from eventlet.patcher import is_monkey_patched
            monkey_patched = is_monkey_patched('socket')
        elif 'gevent' in self.server.async_mode:
            from gevent.monkey import is_module_patched
            monkey_patched = is_module_patched('socket')
        if not monkey_patched:
            raise RuntimeError(
                'Kombu requires a monkey patched socket library to work '
                'with ' + self.server.async_mode) 
开发者ID:miguelgrinberg,项目名称:python-socketio,代码行数:16,代码来源:kombu_manager.py

示例7: initialize

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def initialize(self):
        super(RedisManager, self).initialize()

        monkey_patched = True
        if self.server.async_mode == 'eventlet':
            from eventlet.patcher import is_monkey_patched
            monkey_patched = is_monkey_patched('socket')
        elif 'gevent' in self.server.async_mode:
            from gevent.monkey import is_module_patched
            monkey_patched = is_module_patched('socket')
        if not monkey_patched:
            raise RuntimeError(
                'Redis requires a monkey patched socket library to work '
                'with ' + self.server.async_mode) 
开发者ID:miguelgrinberg,项目名称:python-socketio,代码行数:16,代码来源:redis_manager.py

示例8: _monitor_vm_failover

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def _monitor_vm_failover(self, watcher, callback,
                             event_timeout_ms=_WMI_EVENT_TIMEOUT_MS):
        """Creates a monitor to check for new WMI MSCluster_Resource

        events.

        This method will poll the last _WMI_EVENT_CHECK_INTERVAL + 1
        seconds for new events and listens for _WMI_EVENT_TIMEOUT_MS
        milliseconds, since listening is a thread blocking action.

        Any event object caught will then be processed.
        """

        vm_name = None
        new_host = None
        try:
            # wait for new event for _WMI_EVENT_TIMEOUT_MS milliseconds.
            if patcher.is_monkey_patched('thread'):
                wmi_object = tpool.execute(watcher,
                                           event_timeout_ms)
            else:
                wmi_object = watcher(event_timeout_ms)

            old_host = wmi_object.previous.OwnerNode
            new_host = wmi_object.OwnerNode
            # wmi_object.Name field is of the form:
            # 'Virtual Machine nova-instance-template'
            # wmi_object.Name filed is a key and as such is not affected
            # by locale, so it will always be 'Virtual Machine'
            match = self._instance_name_regex.search(wmi_object.Name)
            if match:
                vm_name = match.group(1)

            if vm_name:
                try:
                    callback(vm_name, old_host, new_host)
                except Exception:
                    LOG.exception(
                        "Exception during failover callback.")
        except exceptions.x_wmi_timed_out:
            pass 
开发者ID:openstack,项目名称:os-win,代码行数:43,代码来源:clusterutils.py

示例9: get_vnic_event_listener

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def get_vnic_event_listener(self, event_type):
        query = self._get_event_wql_query(cls=self._VNIC_SET_DATA,
                                          event_type=event_type,
                                          timeframe=2)
        listener = self._conn.Msvm_SyntheticEthernetPortSettingData.watch_for(
            query)

        def _poll_events(callback):
            if patcher.is_monkey_patched('thread'):
                listen = functools.partial(tpool.execute, listener,
                                           self._VNIC_LISTENER_TIMEOUT_MS)
            else:
                listen = functools.partial(listener,
                                           self._VNIC_LISTENER_TIMEOUT_MS)

            while True:
                # Retrieve one by one all the events that occurred in
                # the checked interval.
                try:
                    event = listen()
                    if event.ElementName:
                        callback(event.ElementName)
                    else:
                        LOG.warning("Ignoring port event. "
                                    "The port name is missing.")
                except exceptions.x_wmi_timed_out:
                    # no new event published.
                    pass

        return _poll_events 
开发者ID:openstack,项目名称:os-win,代码行数:32,代码来源:networkutils.py

示例10: get_vm_power_state_change_listener

# 需要导入模块: from eventlet import patcher [as 别名]
# 或者: from eventlet.patcher import is_monkey_patched [as 别名]
def get_vm_power_state_change_listener(
            self, timeframe=_DEFAULT_EVENT_CHECK_TIMEFRAME,
            event_timeout=constants.DEFAULT_WMI_EVENT_TIMEOUT_MS,
            filtered_states=None, get_handler=False):
        field = self._VM_ENABLED_STATE_PROP
        query = self._get_event_wql_query(cls=self._COMPUTER_SYSTEM_CLASS,
                                          field=field,
                                          timeframe=timeframe,
                                          filtered_states=filtered_states)
        listener = self._conn.Msvm_ComputerSystem.watch_for(raw_wql=query,
                                                            fields=[field])

        def _handle_events(callback):
            if patcher.is_monkey_patched('thread'):
                # Retrieve one by one all the events that occurred in
                # the checked interval.
                #
                # We use eventlet.tpool for retrieving the events in
                # order to avoid issues caused by greenthread/thread
                # communication. Note that PyMI must use the unpatched
                # threading module.
                listen = functools.partial(tpool.execute, listener,
                                           event_timeout)
            else:
                listen = functools.partial(listener, event_timeout)

            while True:
                try:
                    event = listen()

                    vm_name = event.ElementName
                    vm_state = event.EnabledState
                    vm_power_state = self.get_vm_power_state(vm_state)

                    try:
                        callback(vm_name, vm_power_state)
                    except Exception:
                        err_msg = ("Executing VM power state change "
                                   "event callback failed. "
                                   "VM name: %(vm_name)s, "
                                   "VM power state: %(vm_power_state)s.")
                        LOG.exception(err_msg,
                                      dict(vm_name=vm_name,
                                           vm_power_state=vm_power_state))
                except exceptions.x_wmi_timed_out:
                    pass
                except Exception:
                    LOG.exception(
                        "The VM power state change event listener "
                        "encountered an unexpected exception.")
                    time.sleep(event_timeout / 1000)

        return _handle_events if get_handler else listener 
开发者ID:openstack,项目名称:os-win,代码行数:55,代码来源:vmutils.py


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