Message402762
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. |
|
Date |
User |
Action |
Args |
2021-09-28 09:54:32 | whitestockingirl | set | recipients:
+ whitestockingirl, asvetlov, yselivanov |
2021-09-28 09:54:32 | whitestockingirl | set | messageid: <1632822872.87.0.0190246614717.issue45309@roundup.psfhosted.org> |
2021-09-28 09:54:32 | whitestockingirl | link | issue45309 messages |
2021-09-28 09:54:32 | whitestockingirl | create | |
|