本文整理汇总了Python中asyncio.Queue类的典型用法代码示例。如果您正苦于以下问题:Python Queue类的具体用法?Python Queue怎么用?Python Queue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Queue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class MagicEmotiv:
def __init__(self, ptr, upd_interval):
self.data_to_send = Queue()
self.battery = 40
self.packets = Queue()
self.ptr = ptr
self.poll_interval = upd_interval
def set_filter(self, value):
self.poll_interval = 1 / value
async def setup(self):
print("creating magic emotiv...")
async def read_data(self):
while self.running:
s = {}
for shift, sensor in enumerate(sorted(sensor_bits, reverse=True)):
s[sensor] = {'quality': 0.0}
s[sensor]['value'] = np.random.normal() + shift * 5
packet = MagicPacket(
b'Py2\x18\xe7\xb7\xdf\x8e\x86n;g\xbd\xc0\x00\x00\x02\x11(!`' +
b'=\x80\x15\xecX\xc6 \xd9ii\x9e',
s, False)
self.packets.put_nowait(packet)
self.data_to_send.put_nowait(packet)
self.ptr += 1
await asyncio.sleep(self.poll_interval)
async def update_console(self):
while self.running:
packet = await self.packets.get()
print(packet)
await asyncio.sleep(self.poll_interval)
示例2: __init__
def __init__(
self, display_output=False, serial_number="",
is_research=False, filter_hz=25, pointer=0):
"""
Sets up initial values.
"""
self.running = True
self.packets = Queue()
self.data_to_send = Queue()
self.battery = 0
self.display_output = display_output
self.poll_interval = 1 / filter_hz
self.is_research = is_research
self.ptr = pointer
self.sensors = {
'F3': {'value': 0, 'quality': 0},
'FC6': {'value': 0, 'quality': 0},
'P7': {'value': 0, 'quality': 0},
'T8': {'value': 0, 'quality': 0},
'F7': {'value': 0, 'quality': 0},
'F8': {'value': 0, 'quality': 0},
'T7': {'value': 0, 'quality': 0},
'P8': {'value': 0, 'quality': 0},
'AF4': {'value': 0, 'quality': 0},
'F4': {'value': 0, 'quality': 0},
'AF3': {'value': 0, 'quality': 0},
'O2': {'value': 0, 'quality': 0},
'O1': {'value': 0, 'quality': 0},
'FC5': {'value': 0, 'quality': 0},
'X': {'value': 0, 'quality': 0},
'Y': {'value': 0, 'quality': 0},
'Unknown': {'value': 0, 'quality': 0}
}
self.serial_number = serial_number
self.old_model = False
示例3: process_partitions_queue
async def process_partitions_queue(
loop: asyncio.BaseEventLoop,
partitions_queue: asyncio.Queue,
results_queue: asyncio.Queue,
server_address: URL,
mission_template: Template,
mission_loader: str,
width: int,
scale: int,
) -> Awaitable[None]:
mission_name = mission_loader.split('/', 1)[0]
async with aiohttp.ClientSession() as http:
while True:
partition = await partitions_queue.get()
if partition is None:
partitions_queue.task_done()
return
await process_partition(
loop=loop,
results_queue=results_queue,
server_address=server_address,
http=http,
partition=partition,
mission_template=mission_template,
mission_loader=mission_loader,
mission_name=mission_name,
width=width,
scale=scale,
)
partitions_queue.task_done()
示例4: test_nonmatching
def test_nonmatching():
i_queue = Queue()
o_queue = find_events(i_queue)
for in_string in NONMATCHING_TESTS:
yield from i_queue.put(in_string)
yield from o_queue.get()
示例5: test_matching
def test_matching():
i_queue = Queue()
o_queue = find_events(i_queue)
for in_string, event in MATCHING_TESTS:
yield from i_queue.put(in_string)
ev = yield from o_queue.get()
eq_(ev, event)
示例6: MessageHandler
class MessageHandler(ws.WS):
def __init__(self):
self.queue = Queue()
def get(self):
return self.queue.get()
def on_message(self, websocket, message):
return self.queue.put(message)
示例7: udp_writer
async def udp_writer(s: socket, oqueue: Queue) -> None:
"""Forward packets to the UDP socket."""
while True:
peer, data = await oqueue.get()
try:
s.sendto(data, peer)
finally:
oqueue.task_done()
示例8: new_queue
def new_queue():
global _main_loop
queue = Queue(loop=_main_loop)
def putter(item):
_main_loop.call_soon_threadsafe(queue.put_nowait, item)
queue.put = putter
return queue
示例9: __init__
class Listener:
def __init__(self):
self._messages = Queue()
def __call__(self, channel, message):
self._messages.put_nowait((channel, message))
def get(self):
return self._messages.get()
示例10: Message
class Message(ws.WS):
def __init__(self, loop):
self.queue = Queue(loop=loop)
def get(self):
return self.queue.get()
def on_message(self, websocket, message):
self.queue.put_nowait(message)
示例11: call
async def call(loop, inq: asyncio.Queue):
while True:
v = await inq.get()
logger.debug("consume[S] v:%s", v)
if v is None:
inq.task_done()
break
v = await afn(v)
logger.debug("consume[E] v:%s", v)
inq.task_done()
await inq.join()
logger.debug("consume[CLOSE]")
示例12: __call__
async def __call__(self, inq: asyncio.Queue):
while True:
v = await inq.get()
logger.debug("aggregate[S] v:%s", v)
if v is None:
inq.task_done()
break
await asyncio.sleep(0.1, loop=self.loop)
print(v)
logger.debug("aggregate[E] v:%s", v)
inq.task_done()
await inq.join()
logger.debug("aggregate[CLOSE]")
示例13: __init__
class ConnectionPool:
def __init__(self):
self._config_dict = None
self._queue = Queue()
self._outstanding_connections = WeakSet()
async def get_conn(self):
self._check_config()
try:
while True:
conn = self._queue.get_nowait()
if conn.is_open():
break
try:
await conn.close()
except Exception:
l.debug('Exception in close rethink connection', exc_info=True)
except QueueEmpty:
conn = await r.connect(**self._config_dict)
self._outstanding_connections.add(conn)
return conn
async def put_conn(self, conn):
self._queue.put_nowait(conn)
self._outstanding_connections.remove(conn)
def set_config(self, config):
self._config_dict = config
def get_config(self):
self._check_config()
return self._config_dict
async def teardown(self):
while True:
try:
conn = self._queue.get_nowait()
except QueueEmpty:
break
self._outstanding_connections.add(conn)
for conn in self._outstanding_connections:
try:
await conn.close()
except Exception:
l.debug('Exception in close rethink connection', exc_info=True)
def _check_config(self):
assert self._config_dict is not None, "Did you remember to run resync.setup()?"
示例14: input
def input(self, fd, dst):
q = Queue()
def cb():
q.put_nowait(os.read(fd, 32))
self.loop.add_reader(fd, cb)
try:
while True:
data = yield from q.get()
if not data:
break
yield from send(dst, BYTES, data)
finally:
self.loop.remove_reader(fd)
示例15: __init__
def __init__(self):
self._init_states()
self.remote_address = None
self.remote_port = None
self.client_id = None
self.clean_session = None
self.will_flag = False
self.will_message = None
self.will_qos = None
self.will_retain = None
self.will_topic = None
self.keep_alive = 0
self.publish_retry_delay = 0
self.broker_uri = None
self.username = None
self.password = None
self.cafile = None
self.capath = None
self.cadata = None
self._packet_id = 0
self.parent = 0
# Used to store outgoing ApplicationMessage while publish protocol flows
self.inflight_out = OrderedDict()
# Used to store incoming ApplicationMessage while publish protocol flows
self.inflight_in = OrderedDict()
# Stores messages retained for this session
self.retained_messages = Queue()
# Stores PUBLISH messages ID received in order and ready for application process
self.delivered_message_queue = Queue()