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

Function run_concurrently

Lib/test/support/threading_helper.py:252–273  ·  view source on GitHub ↗

Run the worker function concurrently in multiple threads.

(worker_func, nthreads, args=(), kwargs={})

Source from the content-addressed store, hash-verified

250
251
252def run_concurrently(worker_func, nthreads, args=(), kwargs={}):
253 """
254 Run the worker function concurrently in multiple threads.
255 """
256 barrier = threading.Barrier(nthreads)
257
258 def wrapper_func(*args, **kwargs):
259 # Wait for all threads to reach this point before proceeding.
260 barrier.wait()
261 worker_func(*args, **kwargs)
262
263 with catch_threading_exception() as cm:
264 workers = [
265 threading.Thread(target=wrapper_func, args=args, kwargs=kwargs)
266 for _ in range(nthreads)
267 ]
268 with start_threads(workers):
269 pass
270
271 # If a worker thread raises an exception, re-raise it.
272 if cm.exc_value is not None:
273 raise cm.exc_value

Callers

nothing calls this directly

Calls 3

start_threadsFunction · 0.85
BarrierMethod · 0.80

Tested by

no test coverage detected