Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Open
Description
Bug report
Memory allocated in threads is never freed when using a ThreadPoolExecutor. The expected behavior is that when the executor is shut down, all memory allocated in its threads should be freed. The below code demonstrates this leak in that the the memory usage before allocating memory in threads is significantly less than after.
fromconcurrent.futuresimportThreadPoolExecutor,as_completedimportresourcedefprocess_user(x):returnbytearray(10000000)print('Before',resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024,'MB')defleak_memory():withThreadPoolExecutor(max_workers=20)asexecutor:futures= [executor.submit(process_user,i)foriinrange(100)]forfutureinas_completed(futures):cur=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024print('Step',cur)leak_memory()print('After',resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024,'MB')
Your environment
Python 3.9.x/3.10.x. Mac os and debian.