@@ -118,32 +118,29 @@ def test_stack_size(self):
118
118
thread .stack_size (0 )
119
119
self .assertEqual (thread .stack_size (), 0 , "stack_size not reset to default" )
120
120
121
- # def test__count(self):
122
- # # Test the _count() function.
123
- # orig = thread._count()
124
- # mut = thread.allocate_lock()
125
- # mut.acquire()
126
- # started = []
127
- #
128
- # def task():
129
- # started.append(None)
130
- # mut.acquire()
131
- # mut.release()
132
- # thread.start_new_thread(task, ())
133
- # while not started:
134
- # time.sleep(POLL_SLEEP)
135
- # self.assertEqual(thread._count(), orig + 1)
136
- # # Allow the task to finish.
137
- # mut.release()
138
- # # The only reliable way to be sure that the thread ended from the
139
- # # interpreter's point of view is to wait for the function object to be
140
- # # destroyed.
141
- # done = []
142
- # wr = weakref.ref(task, lambda _: done.append(None))
143
- # del task
144
- # while not done:
145
- # time.sleep(POLL_SLEEP)
146
- # self.assertEqual(thread._count(), orig)
121
+ def test__count (self ):
122
+ # Test the _count() function.
123
+ orig = thread ._count ()
124
+ mut = thread .allocate_lock ()
125
+ mut .acquire ()
126
+ started = []
127
+ done = []
128
+
129
+ def task ():
130
+ started .append (None )
131
+ mut .acquire ()
132
+ mut .release ()
133
+ done .append (None )
134
+
135
+ thread .start_new_thread (task , ())
136
+ while not started :
137
+ time .sleep (POLL_SLEEP )
138
+ self .assertEqual (thread ._count (), orig + 1 )
139
+ # Allow the task to finish.
140
+ mut .release ()
141
+ while not done :
142
+ time .sleep (POLL_SLEEP )
143
+ self .assertEqual (thread ._count (), orig )
147
144
148
145
# def test_save_exception_state_on_error(self):
149
146
# # See issue #14474
0 commit comments