New submission from 穆兰 <whitestocking...@gmail.com>: The server code:
import asyncio import struct counter = 0 async def on_connection(r: asyncio.StreamReader, w: asyncio.StreamWriter): msg = struct.pack("HB", 3, 0) w.write(msg) await w.drain() global counter counter += 1 print(counter, "client") async def main(): server = await asyncio.start_server(on_connection, '0.0.0.0', 12345) await server.serve_forever() if __name__ == "__main__": asyncio.run(main()) The client code: import asyncio loop = asyncio.get_event_loop() counter = 0 c_counter = 0 async def connection_to(): r, w = await asyncio.open_connection('192.168.3.2', 12345) global c_counter c_counter += 1 print(c_counter, "connected") await r.readexactly(3) global counter counter += 1 print(counter, "get_msg") async def main(): for i in range(7000): t = loop.create_task(connection_to()) try: loop.run_until_complete(main()) loop.run_forever() except Exception as e: print(e.with_traceback(None)) I open the server on wsl debian and run the client on host windows. Try start more client at once, Then you will find that counter is not equal to c_counter. It nearly always happend. Now I can not trust create_task any more. ---------- components: asyncio messages: 402762 nosy: asvetlov, whitestockingirl, yselivanov priority: normal severity: normal status: open title: asyncio task can not be used to open_connection and read data. type: crash versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45309> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com