Код: Выделить всё
async def read_data(self, stream: UStreams) -> None:
while True:
read_bytes = await stream.read(MAX)
#handle the bytes
Я бы хотел, чтобы эта функция выполняла это, но также завершала работу (поэтому выйти из функции) в случае возникновения события:
Код: Выделить всё
async def read_data(self, stream: UStreams, evt: trio.Event) -> None:
while True:
read_bytes = await stream.read(MAX) || await evt.wait() #
Подробнее здесь: [url]https://stackoverflow.com/questions/78722956/python-await-to-read-from-socket-or-shut-down-on-event[/url]