MCPcopy Index your code
hub / github.com/nodejs/node / drain_queue_async

Function drain_queue_async

deps/v8/tools/testrunner/local/pool.py:111–137  ·  view source on GitHub ↗

Drains a queue in a background thread until the wrapped code unblocks. This can be used to unblock joining a child process that might still write to the queue. The join should be wrapped by this context manager.

(queue)

Source from the content-addressed store, hash-verified

109
110@contextmanager
111def drain_queue_async(queue):
112 """Drains a queue in a background thread until the wrapped code unblocks.
113
114 This can be used to unblock joining a child process that might still write
115 to the queue. The join should be wrapped by this context manager.
116 """
117 keep_running = True
118
119 def empty_queue():
120 elem_count = 0
121 while keep_running:
122 try:
123 while True:
124 queue.get(True, 0.1)
125 elem_count += 1
126 if elem_count < 200:
127 logging.info('Drained an element from queue.')
128 except Empty:
129 pass
130 except:
131 logging.exception('Error draining queue.')
132
133 emptier = threading.Thread(target=empty_queue)
134 emptier.start()
135 yield
136 keep_running = False
137 emptier.join()
138
139
140class ContextPool():

Callers 2

testDrainQueueAsyncMethod · 0.90
_terminateMethod · 0.85

Calls 2

startMethod · 0.45
joinMethod · 0.45

Tested by 1

testDrainQueueAsyncMethod · 0.72