Skip to content

run_in_executor not stopping thread after task cancellation in asyncio (Python 3.11) #107505

Description

@dvir3211

Bug report

A clear and concise description of the bug

The run_in_executor function in asyncio does not stop the thread after task cancellation.

Steps to Reproduce

import asyncio
import time

def runner():
    while True:
        print('Running.')
        time.sleep(1)

async def test():
    task = asyncio.get_event_loop().run_in_executor(None, runner)
    task.cancel()
    await task

asyncio.get_event_loop().run_until_complete(test()) 

Expected Behavior

The run_in_executor function should stop the thread and terminate the task when it is canceled.

Actual Behavior

The run_in_executor function does not stop the thread and the task continues to run even after it is canceled.

Your environment

  • CPython versions tested on: python3.11
  • Operating system and architecture: macOS M1

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions