@@ -321,27 +321,30 @@ PYBIND11_MODULE(eth_validator_watcher_ext, m) {
321321 std::size_t chunk = (vals.size () / n) + 1 ;
322322 std::vector<std::thread> threads;
323323 std::vector<std::map<std::string, MetricsByLabel>> thread_metrics (n);
324+ std::map<std::string, MetricsByLabel> metrics;
324325
325- for (size_t i = 0 ; i < n; i++) {
326- threads.push_back (std::thread ([slot, i, chunk, &vals, &thread_metrics] {
327- std::size_t from = i * chunk;
328- std::size_t to = std::min (from + chunk, vals.size ());
329- process (slot, from, to, vals, thread_metrics[i]);
330- }));
331- }
326+ {
327+ py::gil_scoped_release release;
328+ for (size_t i = 0 ; i < n; i++) {
329+ threads.push_back (std::thread ([slot, i, chunk, &vals, &thread_metrics] {
330+ std::size_t from = i * chunk;
331+ std::size_t to = std::min (from + chunk, vals.size ());
332+ process (slot, from, to, vals, thread_metrics[i]);
333+ }));
334+ }
332335
333- for (auto & thread: threads) {
334- thread.join ();
335- }
336+ for (auto & thread: threads) {
337+ thread.join ();
338+ }
336339
337- std::map<std::string, MetricsByLabel> metrics;
338- merge (thread_metrics, &metrics);
340+ merge (thread_metrics, & metrics) ;
341+ }
339342
340343 py::dict pymetrics;
341344 for (const auto & [label, metric]: metrics) {
342345 pymetrics[py::str (label)] = metric;
343346 }
344-
347+
345348 return pymetrics;
346349 });
347350}
0 commit comments