Hi,
I have a USB device which sometimes disappears unexpectedly for a few ms and I'm trying to handle this cleanly in application-level code -- similar to issue #64, I get an OSError back from a read call, and need to respond by closing and waiting to reopen the device.
I'm using async_read_one(). Unfortunately when the underlying (synchronous) read_one() call raises an exception, the exception leaks out of the future into the event loop. The fix that worked for me is to catch it and attach it to the future:
def async_read_one(self):
future = asyncio.Future()
def read_next():
try:
future.set_result(self.read_one())
except Exception as ex:
future.set_exception(ex)
self._do_when_readable(read_next)
return future
Hi,
I have a USB device which sometimes disappears unexpectedly for a few ms and I'm trying to handle this cleanly in application-level code -- similar to issue #64, I get an OSError back from a read call, and need to respond by closing and waiting to reopen the device.
I'm using
async_read_one(). Unfortunately when the underlying (synchronous)read_one()call raises an exception, the exception leaks out of the future into the event loop. The fix that worked for me is to catch it and attach it to the future: