Message350523
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()) |
|
Date |
User |
Action |
Args |
2019-08-26 10:51:15 | asvetlov | set | recipients:
+ asvetlov, yselivanov, pablogsal, Tianshu Gao |
2019-08-26 10:51:15 | asvetlov | set | messageid: <1566816675.42.0.668636694944.issue37909@roundup.psfhosted.org> |
2019-08-26 10:51:15 | asvetlov | link | issue37909 messages |
2019-08-26 10:51:14 | asvetlov | create | |
|