[issue43991] asyncio lock does not get released after task is canceled

2021-04-30 Thread Alexander Niederbühl

New submission from Alexander Niederbühl :

If a task gets canceled while holding a lock, the lock is not automatically 
released. Is that expected, it seems like it could cause a deadlock?

Failing test adapted from Lib/test/test_asyncio/test_locks.py (commit 
6bd9288b80):

def test_acquire_cancel(self):
lock = asyncio.Lock()
self.assertTrue(self.loop.run_until_complete(lock.acquire()))

task = self.loop.create_task(lock.acquire())
self.loop.call_soon(task.cancel)
self.assertRaises(
asyncio.CancelledError,
self.loop.run_until_complete, task)
self.assertFalse(lock._waiters)

# Should the lock get released after cancellation?
self.assertFalse(lock.locked())

I stumbled upon this while playing around with TLA+.

--
components: asyncio
messages: 392499
nosy: a.niederbuehl, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: asyncio lock does not get released after task is canceled
type: behavior

___
Python tracker 
<https://bugs.python.org/issue43991>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43991] asyncio lock does not get released after task is canceled

2021-05-03 Thread Alexander Niederbühl

Alexander Niederbühl  added the comment:

That makes sense, thanks!

--
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue43991>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com