Skip to content

Commit

Permalink
Do not use the deprecated trio.run_sync_in_worker_thread.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
codypiersall committed Aug 15, 2019
1 parent fc88144 commit baaee03
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/pair1_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit baaee03

Please sign in to comment.