python - How can I close a DatagramTransport as soon one datagram is sent? -
i'm trying close transport right after sending udp packet , i'm getting exception in callback _selectordatagramtransport._read_ready() import asyncio class myprotocol: def __init__(self, message, loop): self.message = message self.loop = loop self.transport = none def connection_made(self, transport): self.transport = transport print("send:", self.message) self.transport.sendto(self.message.encode()) self.transport.close() # <---------- def error_received(self, exc): print('error received', exc) def connection_lost(self, exc): print("socket closed, stop event loop") self.loop.stop() loop = asyncio.get_event_loop() message = "hello" connect = loop.create_datagram_endpoint(lambda: myprotocol(message, loop), remote_addr=('127.0.0.1', 2222)) transport, protocol = loop.run_until_complete(connect) loop.run_forever() the full...