@@ -113,36 +113,29 @@ Reading events from a single device in an endless loop.
113113 key event at 1337016190.284160, 57 (KEY_SPACE), up
114114
115115
116- Reading events (using :mod: `asyncore `)
116+ Reading events (using :mod: `asyncio `)
117117======================================
118118
119+ .. note ::
120+
121+ This requires Python 3.5+ for the async/await keywords.
122+
123+
119124::
120125
121- >>> from asyncore import file_dispatcher, loop
126+ >>> from asyncio import get_event_loop
122127 >>> from evdev import InputDevice, categorize, ecodes
123128 >>> dev = InputDevice('/dev/input/event1')
124129
125- >>> class InputDeviceDispatcher(file_dispatcher):
126- ... def __init__(self, device):
127- ... self.device = device
128- ... file_dispatcher.__init__(self, device)
129- ...
130- ... def recv(self, ign=None):
131- ... return self.device.read()
132- ...
133- ... def handle_read(self):
134- ... for event in self.recv():
135- ... print(repr(event))
136-
137- >>> InputDeviceDispatcher(dev)
138- >>> loop()
139- InputEvent(1337255905L, 358854L, 1, 30, 0L)
140- InputEvent(1337255905L, 358857L, 0, 0, 0L)
141-
142- .. note ::
130+ >>> async def helper(d):
131+ ... async for ev in d.async_read_loop():
132+ ... print(repr(ev))
143133
144- The :mod: `asyncore ` module is deprecated in recent versions of Python.
145- Please consider using :mod: `asyncio `.
134+ >>> loop = asyncio.get_event_loop()
135+ >>> loop.run_until_complete(helper(d))
136+ InputEvent(1527363738, 348740, 4, 4, 458792)
137+ InputEvent(1527363738, 348740, 1, 28, 0)
138+ InputEvent(1527363738, 348740, 0, 0, 0)
146139
147140
148141Reading events from multiple devices (using :mod: `select `)
0 commit comments