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.

Author asvetlov
Recipients Tianshu Gao, asvetlov, pablogsal, yselivanov
Date 2019-08-26.10:51:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1566816675.42.0.668636694944.issue37909@roundup.psfhosted.org>
In-reply-to
Content
In asyncio code please use non-blocking code and await a future returned by run_until_complete.

The following code doesn't leak:

import asyncio
import concurrent
import threading


def prepare_a_giant_list():
    m = []
    for i in range(1000*1000):
        m.append("There's a fat fox jump over a sheep" + str(i))

    th_num = threading.active_count()
    print("Thread number is {}".format(th_num))
    return m


async def main():
    loop = asyncio.get_running_loop()
    async_executor = concurrent.futures.ThreadPoolExecutor(max_workers=20)
    await loop.run_in_executor(async_executor, prepare_a_giant_list)
    await asyncio.sleep(15)
    await loop.run_in_executor(async_executor, prepare_a_giant_list)
    await asyncio.sleep(15)
    await loop.run_in_executor(async_executor, prepare_a_giant_list)
    await asyncio.sleep(15)
    await loop.run_in_executor(async_executor, prepare_a_giant_list)
    await asyncio.sleep(15)


if __name__ == "__main__":
    asyncio.run(main())
History
Date User Action Args
2019-08-26 10:51:15asvetlovsetrecipients: + asvetlov, yselivanov, pablogsal, Tianshu Gao
2019-08-26 10:51:15asvetlovsetmessageid: <1566816675.42.0.668636694944.issue37909@roundup.psfhosted.org>
2019-08-26 10:51:15asvetlovlinkissue37909 messages
2019-08-26 10:51:14asvetlovcreate