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


Python gevent.hub方法代码示例

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


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

示例1: exit

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import hub [as 别名]
def exit(self, signal=None):
        """ Handle an exit request """
        self.logger.info("{} {}".format(signal, "*" * 80))
        # Kill the top level greenlet
        gevent.kill(gevent.hub.get_hub().parent) 
开发者ID:simplecrypto,项目名称:powerpool,代码行数:7,代码来源:main.py

示例2: event_loop

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import hub [as 别名]
def event_loop(self):
        try:
            for fn, args, kwargs in self.queue:
                try:
                    fn(*args, **kwargs)
                except (v8.JSError, JSRuntimeException) as e:
                    self.log_output("Error running asynchronous JavaScript:")
                    self.log_output(e.stackTrace)
        except gevent.hub.LoopExit:
            logger.warning("Runtime ran out of events; terminating.") 
开发者ID:pebble,项目名称:pypkjs,代码行数:12,代码来源:runtime.py

示例3: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import hub [as 别名]
def __init__(self,
                 blocking_sample_period=BLOCKING_SAMPLE_PERIOD,
                 sampling_interval=GREENLET_SAMPLING_INTERVAL,
                 logging_interval=LOGGING_INTERVAL):
        self.blocking_sample_period = blocking_sample_period
        self.sampling_interval = sampling_interval
        self.logging_interval = logging_interval

        self.time_spent_by_context = collections.defaultdict(float)
        self.total_switches = 0
        self._last_switch_time = None
        self._switch_flag = False
        self._active_greenlet = None
        self._main_thread_id = gevent._threading.get_ident()
        self._hub = gevent.hub.get_hub()
        self.last_logged_stats = time.time()
        self.last_checked_blocking = time.time()

        self.total_cpu_time = 0
        self.process = psutil.Process()
        self.pending_avgs = {1: 0, 5: 0, 15: 0}
        self.cpu_avgs = {1: 0, 5: 0, 15: 0}
        self.hostname = socket.gethostname().replace(".", "-")
        self.process_name = str(config.get("PROCESS_NAME", "unknown"))
        # We need a new client instance here because this runs in its own
        # thread.
        self.statsd_client = get_statsd_client()
        self.start_time = time.time() 
开发者ID:nylas,项目名称:sync-engine,代码行数:30,代码来源:instrumentation.py

示例4: stats

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import hub [as 别名]
def stats(self):
        total_time = time.time() - self.start_time
        idle_fraction = self.time_spent_by_context.get('hub', 0) / total_time
        return {
            'times': self.time_spent_by_context,
            'idle_fraction': idle_fraction,
            'total_time': total_time,
            'pending_avgs': self.pending_avgs,
            'cpu_avgs': self.cpu_avgs,
            'total_switches': self.total_switches
        } 
开发者ID:nylas,项目名称:sync-engine,代码行数:13,代码来源:instrumentation.py

示例5: _trace

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import hub [as 别名]
def _trace(self, event, xxx_todo_changeme):
        (origin, target) = xxx_todo_changeme
        self.total_switches += 1
        current_time = time.time()
        if self._last_switch_time is not None:
            time_spent = current_time - self._last_switch_time
            if origin is not self._hub:
                context = getattr(origin, 'context', None)
            else:
                context = 'hub'
            self.time_spent_by_context[context] += time_spent
        self._active_greenlet = target
        self._last_switch_time = current_time
        self._switch_flag = True 
开发者ID:nylas,项目名称:sync-engine,代码行数:16,代码来源:instrumentation.py

示例6: _make_gevent

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import hub [as 别名]
def _make_gevent():
    import gevent
    import gevent.hub
    import gevent.queue
    import greenlet
    
    # We're importing socket to handle an known error in libev on Windows
    # See rgalanakis/goless#28 and surfly/gevent#459
    import socket

    deadlock_errtypes = (gevent.hub.LoopExit,)
    if _os.name == 'nt':
        deadlock_errtypes += (SystemError,)

    class Channel(gevent.queue.Channel):
        def send(self, value):
            with as_deadlock(deadlock_errtypes):
                self.put(value)

        def receive(self):
            with as_deadlock(deadlock_errtypes):
                return self.get()

    class GeventBackend(Backend):
        def shortname(self):
            return 'gevent'  # pragma: no cover

        def start(self, func, *args, **kwargs):
            grnlet = gevent.spawn(func, *args, **kwargs)
            return grnlet

        def run(self, func, *args, **kwargs):
            grnlet = self.start(func, *args, **kwargs)
            self.yield_()
            return grnlet

        def channel(self):
            return Channel()

        def yield_(self):
            with as_deadlock(gevent.hub.LoopExit):
                gevent.sleep()

        def resume(self, tasklet):
            self.yield_()

        def propagate_exc(self, errtype, *args):
            raise errtype

        def would_deadlock(self):
            # The Hub and main greenlet are always running,
            # if there are more than those alive, we aren't going to deadlock.
            count = 0
            for obj in _gc.get_objects():
                if isinstance(obj, greenlet.greenlet) and not obj.dead:
                    count += 1
                    if count > 2:
                        return False
            return True

    return GeventBackend() 
开发者ID:rgalanakis,项目名称:goless,代码行数:63,代码来源:backends.py


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