Skip to content

Deadlock on KeyboardInterrupt in asyncio context #88

Open
@ghost

Description

The following program raises a KeyboardInterrupt from an asyncio context. It prints

MARK
MARK
MARK
raising

and then hangs. The use of the nursery here is just to demonstrate that the mark function isn't being run anymore.
I would expect the program to die with a KeyboardInterrupt Error, but it just hangs and pressing Control-C also doesn't stop the program.

import asyncio

import trio_asyncio
import trio

async def mark():
    while 1:
        print("MARK")
        await trio.sleep(1.0)

async def start():
    async def ctrlc_me():
        await asyncio.sleep(2.5)
        print("raising")
        raise KeyboardInterrupt("ctrl-c")

    async with trio.open_nursery() as nursery:
        nursery.start_soon(mark)
        try:
            await trio_asyncio.aio_as_trio(ctrlc_me)
        finally:
            print("DONE")

if __name__ == "__main__":
    trio_asyncio.run(start)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions