This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: loop.run_in_executor creat thread but not destory it after the task run over
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, cielpy, ronaldoussoren, yselivanov
Priority: normal Keywords:

Created on 2020-08-02 06:40 by cielpy, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg374679 - (view) Author: KevinGuo (cielpy) Date: 2020-08-02 06:40
code like this:

import asyncio

import time

import threading

def sync_test():

async def run_test():
    loop = asyncio.get_event_loop()

    for _ in range(10):
    #     r = await loop.getaddrinfo('', 443)
    #     print(r)

        loop.run_in_executor(None, sync_test)

    for t in threading.enumerate():

    while True:
        await asyncio.sleep(1)

after run, the 10 thread will always exist
msg374917 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-08-06 07:19
This is expected behaviour. Run_in_executor uses a concurrent.futures.ThreadPoolExecutor to manage the worker threads. Those threads will get reused when more work is scheduled, and will exit when the runloop is shut down.
msg374920 - (view) Author: KevinGuo (cielpy) Date: 2020-08-06 09:15
OK, thanks for your reply
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85628
2020-08-07 07:33:19ronaldoussorensettype: behavior
resolution: not a bug
2020-08-06 19:16:51Jeffrey.Kintschersetnosy: - Jeffrey.Kintscher
2020-08-06 09:15:37cielpysetstatus: open -> closed
stage: resolved
2020-08-06 09:15:32cielpysetmessages: + msg374920
2020-08-06 07:19:49ronaldoussorensetnosy: + ronaldoussoren
messages: + msg374917
2020-08-06 01:13:28Jeffrey.Kintschersetnosy: + Jeffrey.Kintscher
2020-08-02 06:40:35cielpycreate