File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ dev = [
3939 " sphinx-design" ,
4040 " tox-direct" ,
4141 " types-mock" ,
42+ " psutil" ,
4243]
4344
4445[project .scripts ]
Original file line number Diff line number Diff line change 33import multiprocessing as mp
44import time
55
6+ import psutil
7+
68# Add cothread onto file and import
79import sys
810import os
@@ -169,6 +171,33 @@ def target():
169171 after = time .time ()
170172 assert float (after - before ) > TIMEOUT
171173
174+ def test_threadstate_memory_leak ():
175+ """Test that the memory leak reported in issue #70 is fixed and does not
176+ reoccur"""
177+
178+ process = psutil .Process ()
179+
180+ vms_start = process .memory_info ().vms
181+
182+ def test ():
183+ pass
184+
185+ # Arbitrary large number of spawns. On my machine with the memory leak
186+ # active,this results in a leak of approximately 2GiB.
187+ for i in range (500000 ):
188+ cothread .Spawn (test )
189+ cothread .Yield ()
190+
191+ vms_end = process .memory_info ().vms
192+
193+ print (f"VMS start { vms_start } end { vms_end } diff { vms_end - vms_start } " )
194+
195+ memory_increase = vms_end - vms_start
196+
197+ # With the memory leak fixed, the memory increase on my machine is only
198+ # 16384 bytes. Added an order of magnitude for future safety.
199+ assert memory_increase < 200000
200+
172201
173202if __name__ == '__main__' :
174203 unittest .main (verbosity = 2 )
You can’t perform that action at this time.
0 commit comments