1818import time
1919
2020from _compat import range , thread
21-
22-
23- def dprint (msg ):
24- # Debugging helper to trace thread-related tests.
25- if 1 :
26- print (msg )
21+ from utils import dprint
2722
2823
2924class StressTest (object ):
@@ -35,47 +30,47 @@ def __init__(self):
3530 self .module = runtests
3631 self .done = []
3732
38- def markStart (self ):
33+ def mark_start (self ):
3934 self ._start = time .clock ()
4035
41- def markFinish (self ):
36+ def mark_finish (self ):
4237 self ._finish = time .clock ()
4338
4439 def elapsed (self ):
4540 return self ._finish - self ._start
4641
47- def printGCReport (self ):
42+ def print_gc_report (self ):
4843 for item in gc .get_objects ():
4944 print (item , sys .getrefcount (item ))
5045
51- def runThread (self , iterations ):
46+ def run_thread (self , iterations ):
5247 thread_id = thread .get_ident ()
53- dprint ("thread %s starting..." % thread_id )
48+ dprint ("thread {0} starting..." . format ( thread_id ) )
5449 time .sleep (0.1 )
5550 for i in range (iterations ):
56- dprint ("thread %s iter %d start" % (thread_id , i ))
51+ dprint ("thread {0} iter {1} start" . format (thread_id , i ))
5752 self .module .main ()
58- dprint ("thread %s iter %d end" % (thread_id , i ))
53+ dprint ("thread {0} iter {1} end" . format (thread_id , i ))
5954 self .done .append (None )
60- dprint ("thread %s done" % thread_id )
55+ dprint ("thread {0} done" . format ( thread_id ) )
6156
62- def stressTest (self , iterations = 1 , threads = 1 ):
57+ def stress_test (self , iterations = 1 , threads = 1 ):
6358 args = (iterations ,)
64- self .markStart ()
59+ self .mark_start ()
6560 for _ in range (threads ):
66- thread = threading .Thread (target = self .runThread , args = args )
61+ thread = threading .Thread (target = self .run_thread , args = args )
6762 thread .start ()
6863 while len (self .done ) < (iterations * threads ):
6964 dprint (len (self .done ))
7065 time .sleep (0.1 )
71- self .markFinish ()
66+ self .mark_finish ()
7267 took = self .elapsed ()
73- self .printGCReport ()
68+ self .print_gc_report ()
7469
7570
7671def main ():
7772 test = StressTest ()
78- test .stressTest (2 , 10 )
73+ test .stress_test (2 , 10 )
7974
8075
8176if __name__ == '__main__' :
0 commit comments