當前位置: 首頁>>代碼示例>>Python>>正文


Python asyncio.streams方法代碼示例

本文整理匯總了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) 
開發者ID:c0rvax,項目名稱:project-black,代碼行數:23,代碼來源:dirsearch_task.py

示例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) 
開發者ID:c0rvax,項目名稱:project-black,代碼行數:25,代碼來源:patator_task.py

示例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 
開發者ID:skylander86,項目名稱:lambda-text-extractor,代碼行數:22,代碼來源:client_proto.py

示例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)) 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:14,代碼來源:timing_tcp_server.py

示例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)) 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:14,代碼來源:simple_tcp_server.py

示例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() 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:54,代碼來源:timing_tcp_server.py

示例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() 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:44,代碼來源:simple_tcp_server.py


注:本文中的asyncio.streams方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。