diff options
author | Tamas Nepusz <ntamas@gmail.com> | 2020-11-02 15:48:51 +0100 |
---|---|---|
committer | Tamas Nepusz <ntamas@gmail.com> | 2020-11-02 15:48:51 +0100 |
commit | a57465c94ba3a401531853b42e1bd071bcd2e93c (patch) | |
tree | 8aae0f11811587934731d2ca5e84b33461d88539 | |
parent | 4c739b6be21b0c98324e7b7780d8e712f3ad6db3 (diff) | |
download | urwid-a57465c94ba3a401531853b42e1bd071bcd2e93c.tar.gz |
fix: use trio.lowlevel instead of trio.hazmat with Trio >= 0.15
-rw-r--r-- | urwid/_async_kw_event_loop.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/urwid/_async_kw_event_loop.py b/urwid/_async_kw_event_loop.py index d146a49..4038405 100644 --- a/urwid/_async_kw_event_loop.py +++ b/urwid/_async_kw_event_loop.py @@ -42,7 +42,11 @@ class TrioEventLoop(EventLoop): self._nursery = None self._sleep = trio.sleep - self._wait_readable = trio.hazmat.wait_readable + try: + self._wait_readable = trio.lowlevel.wait_readable + except AttributeError: + # Trio 0.14 or older + self._wait_readable = trio.hazmat.wait_readable def alarm(self, seconds, callback): """Calls `callback()` a given time from now. No parameters are passed @@ -155,12 +159,20 @@ class TrioEventLoop(EventLoop): emulate_idle_callbacks = TrioIdleCallbackInstrument() + try: + add_instrument = self._trio.lowlevel.add_instrument + remove_instrument = self._trio.lowlevel.remove_instrument + except AttributeError: + # Trio 0.14 or older + add_instrument = self._trio.hazmat.add_instrument + remove_instrument = self._trio.hazmat.remove_instrument + with self._trio.MultiError.catch(self._handle_main_loop_exception): - self._trio.hazmat.add_instrument(emulate_idle_callbacks) + add_instrument(emulate_idle_callbacks) try: await self._main_task() finally: - self._trio.hazmat.remove_instrument(emulate_idle_callbacks) + remove_instrument(emulate_idle_callbacks) def watch_file(self, fd, callback): """Calls `callback()` when the given file descriptor has some data |