Skip to content

Instantly share code, notes, and snippets.

@hynek

hynek/t.py Secret

Created January 14, 2020 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hynek/387f44672722171c901b8422320e8f9b to your computer and use it in GitHub Desktop.
Save hynek/387f44672722171c901b8422320e8f9b to your computer and use it in GitHub Desktop.
❯ python t.py
Traceback (most recent call last):
File "t.py", line 7, in tf
await asyncio.wait_for(con.wait(), 10)
File "/Users/hynek/.pyenv/versions/3.8.1/lib/python3.8/asyncio/tasks.py", line 476, in wait_for
await waiter
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "t.py", line 23, in <module>
asyncio.run(f())
File "/Users/hynek/.pyenv/versions/3.8.1/lib/python3.8/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/Users/hynek/.pyenv/versions/3.8.1/lib/python3.8/asyncio/base_events.py", line 612, in run_until_complete
return future.result()
File "t.py", line 19, in f
await t
File "t.py", line 7, in tf
await asyncio.wait_for(con.wait(), 10)
File "/Users/hynek/.pyenv/versions/3.8.1/lib/python3.8/asyncio/locks.py", line 103, in __aexit__
self.release()
File "/Users/hynek/.pyenv/versions/3.8.1/lib/python3.8/asyncio/locks.py", line 229, in release
raise RuntimeError('Lock is not acquired.')
RuntimeError: Lock is not acquired.
import asyncio
async def tf(con):
async with con:
await asyncio.wait_for(con.wait(), 10)
async def f():
con = asyncio.Condition()
t = asyncio.create_task(tf(con))
await asyncio.sleep(1)
t.cancel()
async with con:
con.notify_all()
await t
asyncio.run(f())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment