From baaee035db5cc8a46b96400e4d9e0f5b58bb8a61 Mon Sep 17 00:00:00 2001 From: Cody Piersall Date: Wed, 14 Aug 2019 20:30:10 -0500 Subject: [PATCH] Do not use the deprecated trio.run_sync_in_worker_thread. Trio 0.12 deprecated this method in favor of trio.to_thread.run_sync. Now we try to use that if it's avaialable and fall back otherwise. --- examples/pair1_async.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/pair1_async.py b/examples/pair1_async.py index b14dfa4..3363b52 100644 --- a/examples/pair1_async.py +++ b/examples/pair1_async.py @@ -32,13 +32,20 @@ import trio +try: + run_sync = trio.to_thread.run_sync +except AttributeError: + # versions of trio prior to 0.12.0 used this method + run_sync = trio.run_sync_in_worker_thread + + async def send_eternally(sock): """ Eternally listen for user input in the terminal and send it on all available pipes. """ while True: - stuff = await trio.run_sync_in_worker_thread(input, cancellable=True) + stuff = await run_sync(input, cancellable=True) for pipe in sock.pipes: await pipe.asend(stuff.encode())