本文整理汇总了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
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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
示例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))
示例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)