Как закрыть соединение, созданное с помощью asyncio.open_connection? - PullRequest
0 голосов
/ 01 августа 2020
import asyncio
import threading

async def run_local():
    server_address = 'www.facebook.com'
    server_port = 443

    # server_address = 'localhost'
    # server_port = 9012

    for i in range(3):
        protocol = asyncio.Protocol()

        r, w = await asyncio.open_connection(server_address, server_port)

        print('Opened connection')

        await asyncio.sleep(3)

        print('Try to close connection')

        # writer.close()
        # await writer.wait_closed()
        w.close()
        await w.wait_closed()

        print('Close successfully')

    while True:
        await asyncio.sleep(1)

        for t in threading.enumerate():
            print(t)

asyncio.run(run_local())

после того, как код завершается, всегда выполняется MainThread и ThreadPoolExcutor-0_x, правильно ли это поведение? если нет, как нить уничтожить

...