Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Reentrant locks in asyncio #439

@ZhukovAlexander

Description

@ZhukovAlexander

Since asyncio.Lock is not reentrant, there is no way the same task could acquire the same lock more than once, so the following code will obviously block:

import asyncio

mutex = asyncio.Lock()


async def child_coro():
    async with mutex:
        print('Hello from chile_coro')


async def parent_coro():
    async with mutex:  # the code will block here
        print('Hello from parent_coro')
        await child_coro()

asyncio.get_event_loop().run_until_complete(parent_coro())

Is there any viable reason to implement an asyncio.RLock, similar to a threading.RLock?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions