启动 n_threads 个线程,每线程提交 per_thread 次,返回 (results, errors)。
(engine, n_threads, per_thread)
| 61 | |
| 62 | |
| 63 | def _concurrent_submit(engine, n_threads, per_thread): |
| 64 | """启动 n_threads 个线程,每线程提交 per_thread 次,返回 (results, errors)。""" |
| 65 | results = [] |
| 66 | errors = [] |
| 67 | # 使用屏障让所有线程尽可能同步启动 |
| 68 | barrier = threading.Barrier(n_threads) |
| 69 | threads = [ |
| 70 | threading.Thread( |
| 71 | target=_submit_n, |
| 72 | args=(engine, per_thread, results, errors, barrier), |
| 73 | ) |
| 74 | for _ in range(n_threads) |
| 75 | ] |
| 76 | for t in threads: |
| 77 | t.start() |
| 78 | for t in threads: |
| 79 | t.join(timeout=30) |
| 80 | return results, errors |
| 81 | |
| 82 | |
| 83 | # --------------------------------------------------------------------------- |
no outgoing calls
no test coverage detected