Skip to content

Commit 4ca239a

Browse files
committed
ConflictDetector: kill both tasks
It's not always obvious which task is the "bad guy" when a conflict occurs. If the "legitimate" task crashes and the buggy one, i.e. the one that forgot to take the lock, does not, the backtrace is not helpful. Thus, kill them both.
1 parent 8a2d6bf commit 4ca239a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

trio/_util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,20 @@ class ConflictDetector:
180180
def __init__(self, msg):
181181
self._msg = msg
182182
self._held = False
183-
183+
self._conflicted = False
184+
184185
def __enter__(self):
185186
if self._held:
187+
self._conflicted = True
186188
raise trio.BusyResourceError(self._msg)
187189
else:
188190
self._held = True
189-
191+
190192
def __exit__(self, *args):
191193
self._held = False
194+
if self._conflicted:
195+
self._conflicted = False
196+
raise trio.BusyResourceError(self._msg)
192197

193198

194199
def async_wraps(cls, wrapped_cls, attr_name):

0 commit comments

Comments
 (0)