File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ objgraph==3.6.2
22pytest==8.4.0
33pytest-codspeed==3.2.0
44pytest-cov==6.1.0
5+ psutil==7.0.0
Original file line number Diff line number Diff line change 1+ # Test for memory leaks surrounding deletion of values.
2+ # SEE: https://github.com/aio-libs/multidict/issues/1232
3+
4+ import gc
5+ import sys
6+ import psutil
7+ import os
8+ from multidict import MultiDict
9+
10+ def get_memory_usage ():
11+ process = psutil .Process (os .getpid ())
12+ memory_info = process .memory_info ()
13+ return memory_info .rss / (1024 * 1024 )
14+
15+ keys = [f"X-Any-{ i } " for i in range (1000 )]
16+ headers = {key : key * 2 for key in keys }
17+
18+
19+ def _run_isolated_case () -> None :
20+ for _ in range (10 ):
21+ for _ in range (1000 ):
22+ result = MultiDict ()
23+ result .update (headers )
24+ for k in keys :
25+ result .pop (k )
26+ # popitem() currently is unaffected but the others all have memory leaks...
27+ # result.popone(k)
28+ # result.popall(k)
29+ del result
30+ gc .collect ()
31+ usage = get_memory_usage ()
32+ # We should never go over 100MB
33+ if usage > 100 :
34+ sys .exit (1 )
35+ sys .exit (0 )
36+
37+ if __name__ == "__main__" :
38+ _run_isolated_case ()
39+
Original file line number Diff line number Diff line change 1515 "multidict_extend_multidict.py" ,
1616 "multidict_extend_tuple.py" ,
1717 "multidict_update_multidict.py" ,
18+ "multidict_pop.py"
1819 ),
1920)
2021@pytest .mark .leaks
You can’t perform that action at this time.
0 commit comments