MCPcopy Index your code
hub / github.com/python/cpython / _TriggerThread

Class _TriggerThread

Lib/test/test_queue.py:28–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27# A thread to run a function that unclogs a blocked Queue.
28class _TriggerThread(threading.Thread):
29 def __init__(self, fn, args):
30 self.fn = fn
31 self.args = args
32 self.startedEvent = threading.Event()
33 threading.Thread.__init__(self)
34
35 def run(self):
36 # The sleep isn't necessary, but is intended to give the blocking
37 # function in the main thread a chance at actually blocking before
38 # we unclog it. But if the sleep is longer than the timeout-based
39 # tests wait in their blocking functions, those tests will fail.
40 # So we give them much longer timeout values compared to the
41 # sleep here (I aimed at 10 seconds for blocking functions --
42 # they should never actually wait that long - they should make
43 # progress as soon as we call self.fn()).
44 time.sleep(0.1)
45 self.startedEvent.set()
46 self.fn(*self.args)
47
48
49# Execute a function that blocks, and in a separate thread, a function that

Callers 2

do_blocking_testMethod · 0.85

Calls

no outgoing calls

Tested by 2

do_blocking_testMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…