本文整理汇总了Python中asyncio.streams方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio.streams方法的具体用法?Python asyncio.streams怎么用?Python asyncio.streams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncio
的用法示例。
在下文中一共展示了asyncio.streams方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import streams [as 别名]
def start(self):
await self.all_done.acquire()
await self.set_status('Working', progress=0)
socket_name = '{}.sock'.format(self.task_id)
self.socket_path = os.path.join(os.getcwd(), socket_name)
if os.path.exists(self.socket_path):
os.remove(self.socket_path)
server = await asyncio.streams.start_unix_server(self.client_connected_cb, path=self.socket_path, loop=self.loop)
try:
self.dirsearch_proc = self.loop.run_in_executor(
ProcessPoolExecutor(), start_program, self.target,
self.task_id, self.project_uuid, self.socket_path,
self.params_object
)
except Exception as exc:
print("Exception starting ProcessPoolExecutor", exc)
示例2: start
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import streams [as 别名]
def start(self):
await self.all_done.acquire()
host, port = self.target.split(':')
args = self.params['program'][0] + " host={} port={}".format(host, port)
await self.set_status('Working', progress=0)
socket_name = '{}.sock'.format(self.task_id)
self.socket_path = os.path.join(os.getcwd(), socket_name)
if os.path.exists(self.socket_path):
os.remove(self.socket_path)
await asyncio.streams.start_unix_server(self.client_connected_cb, path=self.socket_path, loop=self.loop)
try:
self.patator_proc = self.loop.run_in_executor(
ProcessPoolExecutor(), start_program, args,
host, port, self.task_id, self.project_uuid,
self.socket_path
)
except Exception as exc:
print("Exception starting ProcessPoolExecutor", exc)
示例3: __init__
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import streams [as 别名]
def __init__(self, *, loop=None, **kwargs):
asyncio.streams.FlowControlMixin.__init__(self, loop=loop)
DataQueue.__init__(self, loop=loop)
self.paused = False
self.transport = None
self.writer = None
self._should_close = False
self._message = None
self._payload = None
self._payload_parser = None
self._reading_paused = False
self._timer = None
self._skip_status = ()
self._tail = b''
self._upgraded = False
self._parser = None
示例4: start
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import streams [as 别名]
def start(self, loop):
"""
Starts the TCP server, so that it listens on port 1234.
For each client that connects, the accept_client method gets
called. This method runs the loop until the server sockets
are ready to accept connections.
"""
self.server = loop.run_until_complete(
asyncio.streams.start_server(self._accept_client,
'127.0.0.1', 12345,
loop=loop))
示例5: start
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import streams [as 别名]
def start(self, loop):
"""
Starts the TCP server, so that it listens on port 12345.
For each client that connects, the accept_client method gets
called. This method runs the loop until the server sockets
are ready to accept connections.
"""
self.server = loop.run_until_complete(
asyncio.streams.start_server(self._accept_client,
'127.0.0.1', 12345,
loop=loop))
示例6: main
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import streams [as 别名]
def main():
loop = asyncio.get_event_loop()
# creates a server and starts listening to TCP connections
server = MyServer()
server.start(loop)
@asyncio.coroutine
def client():
reader, writer = yield from asyncio.streams.open_connection(
'127.0.0.1', 12345, loop=loop)
def send(msg):
print("> " + msg)
writer.write((msg + '\n').encode("utf-8"))
def recv():
msgback = (yield from reader.readline()).decode("utf-8").rstrip()
print("< " + msgback)
return msgback
# send a line
send("add 1 2")
msg = yield from recv()
Ns = list(range(100, 100000, 10000))
times = []
for N in Ns:
t0 = time.time()
send("repeat {} hello world ".format(N))
msg = yield from recv()
assert msg == 'begin'
while True:
msg = (yield from reader.readline()).decode("utf-8").rstrip()
if msg == 'end':
break
t1 = time.time()
dt = t1 - t0
print("Time taken: {:.3f} seconds ({:.6f} per repetition)"
.format(dt, dt/N))
times.append(dt)
writer.close()
yield from asyncio.sleep(0.5)
# creates a client and connects to our server
try:
loop.run_until_complete(client())
server.stop(loop)
finally:
loop.close()
示例7: main
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import streams [as 别名]
def main():
loop = asyncio.get_event_loop()
# creates a server and starts listening to TCP connections
server = MyServer()
server.start(loop)
@asyncio.coroutine
def client():
reader, writer = yield from asyncio.streams.open_connection(
'127.0.0.1', 12345, loop=loop)
def send(msg):
print("> " + msg)
writer.write((msg + '\n').encode("utf-8"))
def recv():
msgback = (yield from reader.readline()).decode("utf-8").rstrip()
print("< " + msgback)
return msgback
# send a line
send("add 1 2")
msg = yield from recv()
send("repeat 5 hello")
msg = yield from recv()
assert msg == 'begin'
while True:
msg = yield from recv()
if msg == 'end':
break
writer.close()
yield from asyncio.sleep(0.5)
# creates a client and connects to our server
try:
loop.run_until_complete(client())
server.stop(loop)
finally:
loop.close()