30

2021 年了, requests 内存泄露的问题解决了吗?如果没解决,怎么解决?

 2 years ago
source link: https://www.v2ex.com/t/783511
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Python

2021 年了, requests 内存泄露的问题解决了吗?如果没解决,怎么解决?

  v2exblog · 6 小时 35 分钟前 · 1068 次点击
这是在网上看到的一篇博客,
https://morningchen.com/2019/12/12/celery-memory-leak/


用 docker 在最新的 python 版本上实验,还是有泄露的情况。有朋友知道怎么办吗?

第 1 条附言  ·  5 小时 38 分钟前

Line # Mem usage Increment Occurences Line Contents

 7  42.5820312500 MiB  42.5820312500 MiB           1   @profile(precision=10)
 8                                         def foo():
 9  42.5820312500 MiB   0.0000000000 MiB           1       gc.collect()
10  43.0156250000 MiB   0.4335937500 MiB           1       print(len(gc.get_objects()))
11  43.0156250000 MiB   0.0000000000 MiB           1       session = requests.Session()
12                                         
13  45.9453125000 MiB   2.9296875000 MiB           1       r = session.get('https://v2ex.com/4')
14  45.9453125000 MiB   0.0000000000 MiB           1       r.close()
15                                         
16  46.2070312500 MiB   0.2617187500 MiB           1       r = session.get('https://v2ex.com')
17  46.2070312500 MiB   0.0000000000 MiB           1       r.close()
18                                         
19  46.2343750000 MiB   0.0273437500 MiB           1       r = session.get('https://v2ex.com/1')
20  46.2343750000 MiB   0.0000000000 MiB           1       r.close()
21                                         
22  46.2421875000 MiB   0.0078125000 MiB           1       r = session.get('https://v2ex.com/2')
23  46.2421875000 MiB   0.0000000000 MiB           1       r.close()
24                                         
25  46.2500000000 MiB   0.0078125000 MiB           1       session.close()
26  46.2500000000 MiB   0.0000000000 MiB           1       del session
27  46.2500000000 MiB   0.0000000000 MiB           1       del r
28                                         
29  46.2500000000 MiB   0.0000000000 MiB           1       gc.collect()
30  46.5390625000 MiB   0.2890625000 MiB           1       print(len(gc.get_objects()))

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK