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


Python janus.Queue方法代码示例

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


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

示例1: execute_write_fn

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def execute_write_fn(self, fn, block=False):
        task_id = uuid.uuid5(uuid.NAMESPACE_DNS, "datasette.io")
        if self._write_queue is None:
            self._write_queue = queue.Queue()
        if self._write_thread is None:
            self._write_thread = threading.Thread(
                target=self._execute_writes, daemon=True
            )
            self._write_thread.start()
        reply_queue = janus.Queue()
        self._write_queue.put(WriteTask(fn, task_id, reply_queue))
        if block:
            result = await reply_queue.async_q.get()
            if isinstance(result, Exception):
                raise result
            else:
                return result
        else:
            return task_id 
开发者ID:simonw,项目名称:datasette,代码行数:21,代码来源:database.py

示例2: client

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def client(tmpdir, loop):
    store = PanStore(tmpdir)
    queue = janus.Queue()
    conf = ServerConfig("example", "https://exapmle.org")
    conf.history_fetch_delay = 0.1

    store.save_server_user("example", "@example:example.org")

    pan_client = PanClient(
        "example",
        store,
        conf,
        "https://example.org",
        queue.async_q,
        "@example:example.org",
        "DEVICEID",
        tmpdir,
        store_class=SqliteStore,
    )

    yield pan_client

    await pan_client.close() 
开发者ID:matrix-org,项目名称:pantalaimon,代码行数:25,代码来源:pan_client_test.py

示例3: test_sync_put_async_join

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_sync_put_async_join(self):
        loop = janus.current_loop()
        q = janus.Queue()

        for i in range(5):
            q.sync_q.put(i)

        async def do_work():
            await asyncio.sleep(1)
            while True:
                await q.async_q.get()
                q.async_q.task_done()

        task = loop.create_task(do_work())

        async def wait_for_empty_queue():
            await q.async_q.join()
            task.cancel()

        await wait_for_empty_queue()

        q.close()
        await q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:25,代码来源:test_mixed.py

示例4: test_async_put_sync_get

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_async_put_sync_get(self):
        loop = janus.current_loop()
        q = janus.Queue()

        def threaded():
            for i in range(5):
                val = q.sync_q.get()
                self.assertEqual(val, i)

        async def go():
            f = loop.run_in_executor(None, threaded)
            for i in range(5):
                await q.async_q.put(i)

            await f
            self.assertTrue(q.async_q.empty())

        for i in range(3):
            await go()

        q.close()
        await q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:24,代码来源:test_mixed.py

示例5: test_sync_join_async_done

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_sync_join_async_done(self):
        loop = janus.current_loop()
        q = janus.Queue()

        def threaded():
            for i in range(5):
                q.sync_q.put(i)
            q.sync_q.join()

        async def go():
            f = loop.run_in_executor(None, threaded)
            for i in range(5):
                val = await q.async_q.get()
                self.assertEqual(val, i)
                q.async_q.task_done()

            self.assertTrue(q.async_q.empty())

            await f

        for i in range(3):
            await go()

        q.close()
        await q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:27,代码来源:test_mixed.py

示例6: test_async_join_async_done

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_async_join_async_done(self):
        loop = janus.current_loop()
        q = janus.Queue()

        def threaded():
            for i in range(5):
                val = q.sync_q.get()
                self.assertEqual(val, i)
                q.sync_q.task_done()

        async def go():
            f = loop.run_in_executor(None, threaded)
            for i in range(5):
                await q.async_q.put(i)

            await q.async_q.join()

            await f
            self.assertTrue(q.async_q.empty())

        for i in range(3):
            await go()

        q.close()
        await q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:27,代码来源:test_mixed.py

示例7: test_get_with_putters

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_get_with_putters(self):
        loop = janus.current_loop()
        _q = janus.Queue(1)
        q = _q.async_q
        q.put_nowait(1)

        fut = loop.create_future()

        async def put():
            t = asyncio.ensure_future(q.put(2))
            await asyncio.sleep(0.01)
            fut.set_result(None)
            return t

        t = await put()

        res = await q.get()
        self.assertEqual(1, res)

        await t
        self.assertEqual(1, q.qsize())

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:27,代码来源:test_async.py

示例8: test_get_cancelled

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_get_cancelled(self):
        loop = janus.current_loop()
        _q = janus.Queue()
        q = _q.async_q

        async def queue_get():
            return await asyncio.wait_for(q.get(), 0.051)

        async def test():
            get_task = loop.create_task(queue_get())
            await asyncio.sleep(0.01)  # let the task start
            q.put_nowait(1)
            return await get_task

        self.assertEqual(1, await test())

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:21,代码来源:test_async.py

示例9: test_get_with_waiting_putters

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_get_with_waiting_putters(self):
        loop = janus.current_loop()
        _q = janus.Queue(maxsize=1)
        q = _q.async_q

        loop.create_task(q.put('a'))
        loop.create_task(q.put('b'))

        await asyncio.sleep(0.01)

        self.assertEqual(await q.get(), 'a')
        self.assertEqual(await q.get(), 'b')

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:18,代码来源:test_async.py

示例10: test_float_maxsize

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_float_maxsize(self):
        _q = janus.Queue(maxsize=1.3)
        q = _q.async_q
        q.put_nowait(1)
        q.put_nowait(2)
        self.assertTrue(q.full())
        self.assertRaises(asyncio.QueueFull, q.put_nowait, 3)

        _q.close()
        await _q.wait_closed()

        _q = janus.Queue(maxsize=1.3)
        q = _q.async_q

        async def queue_put():
            await q.put(1)
            await q.put(2)
            self.assertTrue(q.full())

        await queue_put()

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:26,代码来源:test_async.py

示例11: test_put_cancelled

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_put_cancelled(self):
        loop = janus.current_loop()
        _q = janus.Queue()
        q = _q.async_q

        async def queue_put():
            await q.put(1)
            return True

        async def test():
            return (await q.get())

        t = loop.create_task(queue_put())
        self.assertEqual(1, await test())
        self.assertTrue(t.done())
        self.assertTrue(t.result())

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:22,代码来源:test_async.py

示例12: test_put_with_waiting_getters

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def test_put_with_waiting_getters(self):
        loop = janus.current_loop()
        fut = loop.create_future()

        async def go():
            fut.set_result(None)
            ret = await q.get()
            return ret

        async def put():
            await q.put('a')

        _q = janus.Queue()
        q = _q.async_q
        t = loop.create_task(go())
        await fut
        await put()
        self.assertEqual(await t, 'a')

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed() 
开发者ID:aio-libs,项目名称:janus,代码行数:24,代码来源:test_async.py

示例13: janus_queue_put_async

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def janus_queue_put_async(_janus_queue: Queue, func: Callable, *args, **kwargs):
    await _janus_queue.async_q.put((func, args, kwargs))


# sync put new task to janus queue 
开发者ID:JQ-Networks,项目名称:UnifiedMessageRelay,代码行数:7,代码来源:Helper.py

示例14: janus_queue_put_sync

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def janus_queue_put_sync(_janus_queue: Queue, func: Callable, *args, **kwargs):
    _janus_queue.sync_q.put((func, args, kwargs)) 
开发者ID:JQ-Networks,项目名称:UnifiedMessageRelay,代码行数:4,代码来源:Helper.py

示例15: pan_proxy_server

# 需要导入模块: import janus [as 别名]
# 或者: from janus import Queue [as 别名]
def pan_proxy_server(tempdir, aiohttp_server):
    loop = asyncio.get_event_loop()
    app = web.Application()

    server_name = faker.hostname()

    config = ServerConfig(server_name, urlparse("https://example.org"))

    pan_queue = janus.Queue()
    ui_queue = janus.Queue()

    proxy = ProxyDaemon(
        config.name,
        config.homeserver,
        config,
        tempdir,
        send_queue=pan_queue.async_q,
        recv_queue=ui_queue.async_q,
        proxy=None,
        ssl=False,
        client_store_class=SqliteStore
    )

    app.add_routes([
        web.post("/_matrix/client/r0/login", proxy.login),
        web.get("/_matrix/client/r0/sync", proxy.sync),
        web.get("/_matrix/client/r0/rooms/{room_id}/messages", proxy.messages),
        web.put(
            r"/_matrix/client/r0/rooms/{room_id}/send/{event_type}/{txnid}",
            proxy.send_message
        ),
        web.post("/_matrix/client/r0/user/{user_id}/filter", proxy.filter),
        web.post("/_matrix/client/r0/search", proxy.search),
        web.options("/_matrix/client/r0/search", proxy.search_opts),
    ])

    server = await aiohttp_server(app)

    yield server, proxy, (pan_queue, ui_queue)

    await proxy.shutdown(app) 
开发者ID:matrix-org,项目名称:pantalaimon,代码行数:43,代码来源:conftest.py


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