From d88d00eebf6c9d8645cc1db17a3b83f36182dc03 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Thu, 26 Mar 2026 16:56:36 +0100 Subject: [PATCH] fix: Guard ReentrantLock against None task context Co-Authored-By: Claude Opus 4.6 (1M context) --- src/apify/_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/apify/_utils.py b/src/apify/_utils.py index 38e9a66e..23a75e67 100644 --- a/src/apify/_utils.py +++ b/src/apify/_utils.py @@ -141,6 +141,8 @@ def __init__(self) -> None: async def __call__(self) -> AsyncIterator[None]: """Acquire the lock if it's not already owned by the current task, otherwise proceed without acquiring.""" me = asyncio.current_task() + if me is None: + raise RuntimeError('ReentrantLock must be used within an asyncio.Task') if self._owner is me: yield return