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