Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions lost from async_read_one #67

Closed
0xabu opened this issue Jun 15, 2017 · 1 comment
Closed

Exceptions lost from async_read_one #67

0xabu opened this issue Jun 15, 2017 · 1 comment

Comments

@0xabu
Copy link

@0xabu 0xabu commented Jun 15, 2017

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
@gvalkov

This comment has been minimized.

Copy link
Owner

@gvalkov gvalkov commented Jun 16, 2017

That's a good catch! Thanks - fixed in 388ce6f and released in evdev 0.7.0.

@gvalkov gvalkov closed this Jun 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.