Skip to content

Error after asyncio cancel #123

Open

Description

@charleseidsness

I was getting this trace-back message after cancelling a co-routine that was waiting on an evdev event:

Exception in callback <function EventIO._do_when_readable.<locals>.ready at 0xffff92de3560>
handle: <Handle cancelled>                                            
Traceback (most recent call last):                                    
  File "usr/lib/python3.7/site-packages/evdev/eventio_async.py", line 22, in _set_result
asyncio.base_futures.InvalidStateError: invalid state             
                                                                                                                                             
During handling of the above exception, another exception occurred:
                                                                      
Traceback (most recent call last):                                    
  File "uvloop/cbhandles.pyx", line 68, in uvloop.loop.Handle._run    
  File "usr/lib/python3.7/site-packages/evdev/eventio_async.py", line 17, in ready                                                           
  File "usr/lib/python3.7/site-packages/evdev/eventio_async.py", line 32, in <lambda>
  File "usr/lib/python3.7/site-packages/evdev/eventio_async.py", line 24, in _set_result
asyncio.base_futures.InvalidStateError: invalid state 

I resolved it with this patch

--- python-evdev-1.3.0/evdev/eventio_async.py.orig      2020-04-23 07:10:17.319778548 -0400
+++ python-evdev-1.3.0/evdev/eventio_async.py   2020-04-23 07:11:30.570013920 -0400
@@ -20,6 +20,8 @@
     def _set_result(self, future, cb):
         try:
             future.set_result(cb())
+        except asyncio.InvalidStateError:
+            pass
         except Exception as error:
             future.set_exception(error)

Activity

  1. gfhcs commented on Feb 7, 2023

    @gfhcs

    I was observing a similar issue when working with Bluetooth devices that would sometimes get disconnected while I was waiting for events from them. In my case, the result were not the set_result calls, but the set_exception calls in /evdev/eventio_async.py, because they occured when future.done() was already True. Putting the set_exception calls in a try block like above did resolve my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions