Note that you can wrap any of those methods with an asyncio.wait_for(). try: try: await asyncio.wait_for(lock.acquire(), 1.0) except asyncio.TimeoutError: # times out after 1 second print("deadlock!") return do_things_with_lock() finally: lock.release()
Although I must admit, it would be convenient to have a timeout parameter directly in the methods like acquire, especially because it would make timeouts usable directly in the async context manager: async with lock.acquire(timeout=1.0): do_things_with_lock() On Mon, 20 Sept 2021 at 07:21, Andres Torres <andres.torresh...@gmail.com> wrote: > It would be very nice if the [Synchronization Primitives]( > https://docs.python.org/3/library/asyncio-sync.html) had a timeout > parameter just like the [analogous classes]( > https://docs.python.org/3/library/threading.html#condition-objects) do in > the threading module. > > Thank you for your consideration! > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/6CNWNDZHRVETDH5EFIRMWD42FGD6TTCP/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Gustavo J. A. M. Carneiro Gambit Research "The universe is always one step beyond logic." -- Frank Herbert
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XGJSHB7KW6H4WYFDE73S5HOJC6KPYGVF/ Code of Conduct: http://python.org/psf/codeofconduct/