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


Python gevent.get_hub方法代码示例

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


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

示例1: test_threadpool_resolver_mp

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def test_threadpool_resolver_mp(self):
        h = gevent.get_hub()
        t = h.threadpool
        r = h.resolver
        p = start_process(target=complchild_test_threadpool_resolver_mp)
        # Note(JP): seen this fail once on Windows CI with a timeout of 1 s.
        p.join(timeout=2)
        assert p.exitcode == 0 
开发者ID:jgehrcke,项目名称:gipc,代码行数:10,代码来源:test_gipc.py

示例2: complchild_test_threadpool_resolver_mp

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def complchild_test_threadpool_resolver_mp():
    h = gevent.get_hub()
    t = h.threadpool
    r = h.resolver 
开发者ID:jgehrcke,项目名称:gipc,代码行数:6,代码来源:test_gipc.py

示例3: start

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def start(self):
            # Start grabbing SIGCHLD within libev event loop.
            gevent.get_hub().loop.install_sigchld()
            # Run new process (based on `fork()` on POSIX-compliant systems).
            super(_GProcess, self).start()
            # The occurrence of SIGCHLD is recorded asynchronously in libev.
            # This guarantees proper behavior even if the child watcher is
            # started after the child exits. Start child watcher now.
            self._sigchld_watcher = gevent.get_hub().loop.child(self.pid)
            self._returnevent = gevent.event.Event()
            self._sigchld_watcher.start(
                self._on_sigchld, self._sigchld_watcher)
            log.debug("SIGCHLD watcher for %s started.", self.pid) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:15,代码来源:gipc.py

示例4: get

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def get(self, timeout=None):
        """Receive, decode and return data from the pipe. Block
        gevent-cooperatively until data is available or timeout expires. The
        default decoder is ``pickle.loads``.

        :arg timeout: ``None`` (default) or a ``gevent.Timeout``
            instance. The timeout must be started to take effect and is
            canceled when the first byte of a new message arrives (i.e.
            providing a timeout does not guarantee that the method completes
            within the timeout interval).

        :returns: a Python object.

        Raises:
            - :exc:`gevent.Timeout` (if provided)
            - :exc:`GIPCError`
            - :exc:`GIPCClosed`
            - :exc:`pickle.UnpicklingError`

        Recommended usage for silent timeout control::

            with gevent.Timeout(TIME_SECONDS, False) as t:
                reader.get(timeout=t)

        .. warning::

            The timeout control is currently not available on Windows,
            because Windows can't apply select() to pipe handles.
            An ``OSError`` is expected to be raised in case you set a
            timeout.
        """
        self._validate()
        with self._lock:
            if timeout:
                # Wait for ready-to-read event.
                h = gevent.get_hub()
                h.wait(h.loop.io(self._fd, 1))
                timeout.cancel()
            msize, = struct.unpack("!i", self._recv_in_buffer(4).getvalue())
            bindata = self._recv_in_buffer(msize).getvalue()
        return self._decoder(bindata) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:43,代码来源:gipc.py

示例5: timer

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def timer(after, repeat):
    """
    :param after:
    :param repeat:
    :return:
    """
    return gevent.get_hub().loop.timer(after, repeat) 
开发者ID:cls1991,项目名称:x-proxies,代码行数:9,代码来源:task.py

示例6: wrap_error_fatal

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def wrap_error_fatal(method):
    @wraps(method)
    def wrapped(self, *args, **kwargs):
        # XXX should also be able to do gevent.SYSTEM_ERROR = object
        # which is a global default to all hubs
        SYSTEM_ERROR = gevent.get_hub().SYSTEM_ERROR
        gevent.get_hub().SYSTEM_ERROR = object
        try:
            return method(self, *args, **kwargs)
        finally:
            gevent.get_hub().SYSTEM_ERROR = SYSTEM_ERROR
    return wrapped 
开发者ID:34nm,项目名称:gsmtpd,代码行数:14,代码来源:greentest.py

示例7: wrap_restore_handle_error

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def wrap_restore_handle_error(method):
    @wraps(method)
    def wrapped(self, *args, **kwargs):
        old = gevent.get_hub().handle_error
        try:
            return method(self, *args, **kwargs)
        finally:
            gevent.get_hub().handle_error = old
        if self.peek_error()[0] is not None:
            gevent.getcurrent().throw(*self.peek_error()[1:])
    return wrapped 
开发者ID:34nm,项目名称:gsmtpd,代码行数:13,代码来源:greentest.py

示例8: expect_one_error

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def expect_one_error(self):
        assert self._error == self._none, self._error
        self._old_handle_error = gevent.get_hub().handle_error
        gevent.get_hub().handle_error = self._store_error 
开发者ID:34nm,项目名称:gsmtpd,代码行数:6,代码来源:greentest.py

示例9: _store_error

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def _store_error(self, where, type, value, tb):
        del tb
        if self._error != self._none:
            gevent.get_hub().parent.throw(type, value)
        else:
            self._error = (where, type, value) 
开发者ID:34nm,项目名称:gsmtpd,代码行数:8,代码来源:greentest.py

示例10: run

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def run(ctx, dev):
    """Start the client ( --dev to stop on error)"""
    # create app
    app = EthApp(ctx.obj['config'])

    # development mode
    if dev:
        gevent.get_hub().SYSTEM_ERROR = BaseException
        try:
            ctx.obj['config']['client_version'] += '/' + os.getlogin()
        except:
            log.warn("can't get and add login name to client_version")
            pass

    # dump config
    konfig.dump_config(ctx.obj['config'])

    # register services
    for service in services:
        assert issubclass(service, BaseService)
        if service.name not in app.config['deactivated_services']:
            assert service.name not in app.services
            service.register_with_app(app)
            assert hasattr(app.services, service.name)

    # start app
    app.start()

    # wait for interrupt
    evt = Event()
    gevent.signal(signal.SIGQUIT, evt.set)
    gevent.signal(signal.SIGTERM, evt.set)
    gevent.signal(signal.SIGINT, evt.set)
    evt.wait()

    # finally stop
    app.stop() 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:39,代码来源:app.py

示例11: powworker_process

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def powworker_process(cpipe, cpu_pct):
    "entry point in forked sub processes, setup env"
    gevent.get_hub().SYSTEM_ERROR = BaseException  # stop on any exception
    PoWWorker(cpipe, cpu_pct).run()


# parent process defined below ##############################################3 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:9,代码来源:pow_service.py

示例12: monkey_patch_for_gevent

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def monkey_patch_for_gevent():
    import functools, gevent
    apply_e = gevent.get_hub().threadpool.apply_e
    def monkey_patch(func):
        @functools.wraps(func)
        def wrap(*args, **kwargs):
            #if DEBUG:print('%s called with %s %s' % (func, args, kwargs))
            return apply_e(Exception, func, args, kwargs)
        return wrap
    for attr in dir(ODBC_API):
        if attr.startswith('SQL') and hasattr(getattr(ODBC_API, attr), 'argtypes'):
            setattr(ODBC_API, attr, monkey_patch(getattr(ODBC_API, attr))) 
开发者ID:harryliu,项目名称:edwin,代码行数:14,代码来源:pypyodbc.py

示例13: apply_patch

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def apply_patch(hogging_detection=False, real_threads=1):
    _logger.info('applying gevent patch (%s real threads)', real_threads)

    # real_threads is 1 by default so it will be possible to run watch_threads concurrently
    if hogging_detection:
        real_threads += 1

    if real_threads:
        _RealThreadsPool(real_threads)

    _patch_module_locks()

    import gevent
    import gevent.monkey

    for m in ["easypy.threadtree", "easypy.concurrency"]:
        assert m not in sys.modules, "Must apply the gevent patch before importing %s" % m

    gevent.monkey.patch_all(Event=True, sys=True)

    _unpatch_logging_handlers_lock()

    global HUB
    HUB = gevent.get_hub()

    global threading
    import threading
    for thread in threading.enumerate():
        _set_thread_uuid(thread.ident)
    _set_main_uuid()  # the patched threading has a new ident for the main thread

    # this will declutter the thread dumps from gevent/greenlet frames
    from .threadtree import _BOOTSTRAPPERS
    import gevent, gevent.threading, gevent.greenlet
    _BOOTSTRAPPERS.update([gevent, gevent.threading, gevent.greenlet])

    if hogging_detection:
        import greenlet
        greenlet.settrace(lambda *args: _greenlet_trace_func(*args))
        defer_to_thread(detect_hogging, 'detect-hogging') 
开发者ID:weka-io,项目名称:easypy,代码行数:42,代码来源:gevent.py

示例14: set_up_logging

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def set_up_logging(filename):
    gevent.get_hub().exception_stream = io.StringIO()
    logging.config.dictConfig({
        'version': 1,
        'formatters': {
            'default': {'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s'}
        },
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
                'formatter': 'default',
                'stream': 'ext://sys.stdout'
            },
            'file': {
                'class': 'logging.handlers.RotatingFileHandler',
                'formatter': 'default',
                'filename': filename,
                'maxBytes': 20 * 1024 * 1024,
                'backupCount': 5,
            }
        },
        'loggers': {
            '': {
                'level': 'INFO',
                'handlers': ['console', 'file']
            }
        }
    }) 
开发者ID:Griffon26,项目名称:taserver,代码行数:30,代码来源:logging.py

示例15: main

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import get_hub [as 别名]
def main(recipe_deps, cov_file, is_train, cover_module_imports):
  # TODO(iannucci): Route and log greenlet exception information somewhere
  # useful as part of each test case.
  gevent.get_hub().exception_stream = None

  main_repo = recipe_deps.main_repo

  cov_data = coverage.CoverageData()
  if cover_module_imports:
    cov_data.update(_cover_all_imports(main_repo))

  test_data_cache = {}

  path_cleaner = _make_path_cleaner(recipe_deps)

  fatal = False

  while True:
    test_desc = _read_test_desc()
    if not test_desc:
      break  # EOF or error

    result = Outcome()
    try:
      full_name = '%s.%s' % (test_desc.recipe_name, test_desc.test_name)
      test_result = result.test_results[full_name]

      recipe = main_repo.recipes[test_desc.recipe_name]

      if cov_file:
        # We have to start coverage now because we want to cover the importation
        # of the covered recipe and/or covered recipe modules.
        cov = coverage.Coverage(config_file=False, concurrency='gevent',
                                include=recipe.coverage_patterns)
        cov.start()  # to cover execfile of recipe/module.__init__

      test_data = _get_test_data(test_data_cache, recipe, test_desc.test_name)
      try:
        _run_test(path_cleaner, test_result, recipe_deps, test_desc, test_data,
                  is_train)
      except Exception as ex:  # pylint: disable=broad-except
        test_result.internal_error.append('Uncaught exception: %r' % (ex,))
        test_result.internal_error.extend(traceback.format_exc().splitlines())
      if cov_file:
        cov.stop()
        cov_data.update(cov.get_data())

    except Exception as ex:  # pylint: disable=broad-except
      result.internal_error.append('Uncaught exception: %r' % (ex,))
      result.internal_error.extend(traceback.format_exc().splitlines())
      fatal = True

    if not write_message(sys.stdout, result) or fatal:
      break  # EOF

  if cov_file:
    # Sometimes we stop when the cov_file hasn't gotten created yet
    if os.path.exists(os.path.dirname(cov_file)):
      coverage.data.CoverageDataFiles(basename=cov_file).write(cov_data) 
开发者ID:luci,项目名称:recipes-py,代码行数:61,代码来源:runner.py


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