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


Python pulsar.get_event_loop函数代码示例

本文整理汇总了Python中pulsar.get_event_loop函数的典型用法代码示例。如果您正苦于以下问题:Python get_event_loop函数的具体用法?Python get_event_loop怎么用?Python get_event_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_suite_event_loop

 def test_suite_event_loop(self):
     '''Test event loop in test worker'''
     worker = pulsar.get_actor()
     loop = get_event_loop()
     self.assertTrue(loop.is_running())
     self.assertTrue(worker._loop.is_running())
     self.assertNotEqual(worker._loop, loop)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:7,代码来源:me.py

示例2: test_coroutine1

 def test_coroutine1(self):
     loop = get_event_loop()
     d1 = Future()
     loop.call_later(0.2, d1.set_result, 1)
     a = yield c_summation(d1)
     self.assertEqual(a, 3)
     self.assertEqual(d1.result(), 1)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:7,代码来源:coro.py

示例3: test_chain

 def test_chain(self):
     loop = get_event_loop()
     future = Future()
     next = chain_future(future, callback=lambda r: r+2)
     loop.call_later(0.2, future.set_result, 1)
     result = yield next
     self.assertEqual(result, 3)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:7,代码来源:coro.py

示例4: create_store

def create_store(url, loop=None, **kw):
    '''Create a new client :class:`Store` for a valid ``url``.

    A valid ``url`` taks the following forms::

        pulsar://user:[email protected]:6410
        redis://user:[email protected]:6500/11?namespace=testdb.
        postgresql://user:[email protected]:6500/testdb
        couchdb://user:[email protected]:6500/testdb

    :param loop: optional event loop, if not provided it is obtained
        via the ``get_event_loop`` method. If not loop is installed a bright
        new event loop is created via the :func:`.new_event_loop`.
        In the latter case the event loop is employed only for synchronous type
        requests via the :meth:`~.EventLoop.run_until_complete` method.
    :param kw: additional key-valued parameters to pass to the :class:`Store`
        initialisation method.
    :return: a :class:`Store`.
    '''
    if isinstance(url, Store):
        return url
    scheme, address, params = parse_store_url(url)
    dotted_path = data_stores.get(scheme)
    if not dotted_path:
        raise ImproperlyConfigured('%s store not available' % scheme)
    loop = loop or get_event_loop()
    if not loop:
        loop = new_event_loop(logger=logging.getLogger(dotted_path))
    store_class = module_attribute(dotted_path)
    params.update(kw)
    return store_class(scheme, address, loop, **params)
开发者ID:Ghost-script,项目名称:dyno-chat,代码行数:31,代码来源:base.py

示例5: wait_fd

def wait_fd(fd, read=True):
    '''Wait for an event on file descriptor ``fd``.

    :param fd: file descriptor
    :param read=True: wait for a read event if ``True``, otherwise a wait
        for write event.

    This function must be invoked from a coroutine with parent, therefore
    invoking it from the main greenlet will raise an exception.
    Check how this function is used in the :func:`.psycopg2_wait_callback`
    function.
    '''
    current = greenlet.getcurrent()
    parent = current.parent
    assert parent, '"wait_fd" must be called by greenlet with a parent'
    try:
        fileno = fd.fileno()
    except AttributeError:
        fileno = fd
    loop = get_event_loop()
    future = Future(loop=loop)
    # When the event on fd occurs switch back to the current greenlet
    if read:
        loop.add_reader(fileno, _done_wait_fd, fileno, future, read)
    else:
        loop.add_writer(fileno, _done_wait_fd, fileno, future, read)
    # switch back to parent greenlet
    parent.switch(future)
    return future.result()
开发者ID:JinsongBian,项目名称:pulsar,代码行数:29,代码来源:__init__.py

示例6: test_periodic

    def test_periodic(self):
        test = self
        loop = get_event_loop()
        waiter = Future()

        class p:
            def __init__(self, loops):
                self.loops = loops
                self.c = 0

            def __call__(self):
                self.c += 1
                if self.c == self.loops:
                    try:
                        raise ValueError('test periodic')
                    except Exception:
                        waiter.set_result(self.c)
                        raise

        every = 2
        loops = 2
        track = p(loops)
        start = loop.time()
        periodic = call_repeatedly(loop, every, track)
        self.assertIsInstance(periodic, LoopingCall)
        done = yield waiter
        taken = loop.time() - start
        self.assertEqual(done, loops)
        self.assertTrue(taken > every*loops)
        self.assertTrue(taken < every*loops + 2)
        self.assertTrue(periodic.cancelled)
        self.assertFalse(has_callback(loop, periodic.handler))
开发者ID:axisofentropy,项目名称:pulsar,代码行数:32,代码来源:eventloop.py

示例7: test_call_at

 def test_call_at(self):
     loop = get_event_loop()
     d1 = Future()
     d2 = Future()
     c1 = loop.call_at(loop.time()+1, lambda: d1.set_result(loop.time()))
     c2 = loop.call_later(1, lambda: d2.set_result(loop.time()))
     t1, t2 = yield pulsar.multi_async((d1, d2))
     self.assertTrue(t1 <= t2)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:8,代码来源:eventloop.py

示例8: test_getnameinfo

 def test_getnameinfo(self):
     loop = get_event_loop()
     info = yield from loop.getaddrinfo('www.bbc.co.uk', 'http')
     info = yield from loop.getnameinfo(('212.58.244.66', 80))
     info = yield from loop.getaddrinfo('github.com', 'https')
     self.assertTrue(info)
     addr = info[0][4]
     info = yield from loop.getnameinfo(addr)
     self.assertTrue(info)
开发者ID:arhik,项目名称:pulsar,代码行数:9,代码来源:dns.py

示例9: __init__

 def __init__(self, max_workers=None, loop=None, maxtasks=None):
     self._loop = loop or get_event_loop()
     self._max_workers = min(max_workers or _DEFAULT_WORKERS, _MAX_WORKERS)
     self._greenlets = set()
     self._available = set()
     self._maxtasks = maxtasks
     self._queue = deque()
     self._shutdown = False
     self._shutdown_lock = threading.Lock()
开发者ID:JinsongBian,项目名称:pulsar,代码行数:9,代码来源:pool.py

示例10: _

 def _(o):
     try:
         pool = o.app.green_pool
     except AttributeError:
         pool = None
     if pool:
         return pool.submit(test_fun, o)
     else:
         loop = get_event_loop()
         return loop.run_in_executor(None, test_fun, o)
开发者ID:pvanderlinden,项目名称:lux,代码行数:10,代码来源:test.py

示例11: __init__

 def __init__(self, max_workers=None, loop=None):
     self._loop = loop or get_event_loop()
     self._max_workers = min(max_workers or _DEFAULT_WORKERS, _MAX_WORKERS)
     self._greenlets = set()
     self._available = set()
     self._queue = deque()
     self._shutdown = False
     self._waiter = None
     self._logger = logging.getLogger('pulsar.greenpool')
     self._shutdown_lock = threading.Lock()
开发者ID:artemmus,项目名称:pulsar,代码行数:10,代码来源:__init__.py

示例12: test_call_soon

 def test_call_soon(self):
     ioloop = get_event_loop()
     tid = yield loop_thread_id(ioloop)
     d = Future()
     callback = lambda: d.set_result(current_thread().ident)
     cbk = ioloop.call_soon(callback)
     self.assertEqual(cbk._callback, callback)
     self.assertEqual(cbk._args, ())
     # we should be able to wait less than a second
     result = yield d
     self.assertEqual(result, tid)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:11,代码来源:eventloop.py

示例13: test_pool

 def test_pool(self):
     pool = greenio.GreenPool()
     self.assertTrue(pool._loop)
     self.assertEqual(pool._loop, get_event_loop())
     self.assertFalse(pool._greenlets)
     future = pool.submit(lambda: 'Hi!')
     self.assertIsInstance(future, Future)
     result = yield from future
     self.assertEqual(result, 'Hi!')
     self.assertEqual(len(pool._greenlets), 1)
     self.assertEqual(len(pool._available), 1)
开发者ID:nmg1986,项目名称:pulsar,代码行数:11,代码来源:greenio.py

示例14: run_until_complete

    def run_until_complete(self, options, **params):
        '''Execute the :meth:`run` method using pulsar asynchronous engine.

        Most commands are run using this method.
        '''
        loop = get_event_loop()
        run = run_in_greenlet(self.run)
        result = run(options, **params)
        if not loop.is_running():
            return loop.run_until_complete(result)
        else:
            return result
开发者ID:tourist,项目名称:lux,代码行数:12,代码来源:__init__.py

示例15: run_async

 def run_async(self, argv, **params):
     '''Run a command using pulsar asynchronous engine.'''
     loop = get_event_loop()
     run_until_complete = False
     if loop is None:
         run_until_complete = True
         loop = new_event_loop()
     future = async(self.run(argv, **params), loop)
     if run_until_complete:
         return loop.run_until_complete(future)
     else:
         return future
开发者ID:pombredanne,项目名称:lux,代码行数:12,代码来源:__init__.py


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