concurrent.futures.ThreadPoolExecutor does not free memory when shutdown
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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.
from concurrent.futures import ThreadPoolExecutor, as_completed
import resource
def process_user(x):
return bytearray(10000000)
print('Before', resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024, 'MB')
def leak_memory():
with ThreadPoolExecutor(max_workers=20) as executor:
futures = [executor.submit(process_user, i) for i in range(100)]
for future in as_completed(futures):
cur = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024
print('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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện ví dụ trên Python 3.9 hoặc 3.10 trong macOS hoặc Debian, tập trung vào việc tắt concurrent.futures.ThreadPoolExecutor và phép đo resource.RUSAGE_SELF ru_maxrss. Xác định liệu giá trị được báo cáo có nên giảm sau khi tắt hay không, sau đó xác định phần triển khai hoặc các kiểm thử liên quan và định nghĩa hành vi bộ nhớ dự kiến sau khi tắt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100