MCPcopy Create free account
hub / github.com/Tong89/smartNode / _submit_concurrent

Function _submit_concurrent

tests/load/test_stress_engine.py:107–130  ·  view source on GitHub ↗

多线程并发提交,返回 (results, errors)。

(engine, payload: dict, n_threads: int, per_thread: int)

Source from the content-addressed store, hash-verified

105
106
107def _submit_concurrent(engine, payload: dict, n_threads: int, per_thread: int):
108 """多线程并发提交,返回 (results, errors)。"""
109 results: List[dict] = []
110 errors: List[Exception] = []
111 lock = threading.Lock()
112 barrier = threading.Barrier(n_threads)
113
114 def worker():
115 barrier.wait()
116 for _ in range(per_thread):
117 try:
118 r = engine.submit_request(dict(payload))
119 with lock:
120 results.append(r)
121 except Exception as exc:
122 with lock:
123 errors.append(exc)
124
125 threads = [threading.Thread(target=worker) for _ in range(n_threads)]
126 for t in threads:
127 t.start()
128 for t in threads:
129 t.join(timeout=30)
130 return results, errors
131
132
133def _avg_utilization(engine) -> float:

Calls

no outgoing calls

Tested by

no test coverage detected