MCPcopy Index your code
hub / github.com/RustPython/RustPython / task2

Method task2

Lib/test/test_thread.py:194–217  ·  view source on GitHub ↗
(self, ident)

Source from the content-addressed store, hash-verified

192 verbose_print("tasks done")
193
194 def task2(self, ident):
195 for i in range(NUMTRIPS):
196 if ident == 0:
197 # give it a good chance to enter the next
198 # barrier before the others are all out
199 # of the current one
200 delay = 0
201 else:
202 with self.random_mutex:
203 delay = random.random() / 10000.0
204 verbose_print("task %s will run for %sus" %
205 (ident, round(delay * 1e6)))
206 time.sleep(delay)
207 verbose_print("task %s entering %s" % (ident, i))
208 self.bar.enter()
209 verbose_print("task %s leaving barrier" % ident)
210 with self.running_mutex:
211 self.running -= 1
212 # Must release mutex before releasing done, else the main thread can
213 # exit and set mutex to None as part of global teardown; then
214 # mutex.release() raises AttributeError.
215 finished = self.running == 0
216 if finished:
217 self.done_mutex.release()
218
219class LockTests(lock_tests.LockTests):
220 locktype = thread.allocate_lock

Callers

nothing calls this directly

Calls 6

verbose_printFunction · 0.85
roundFunction · 0.85
randomMethod · 0.45
sleepMethod · 0.45
enterMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected