|
2 | 2 | import time |
3 | 3 | import json |
4 | 4 | from datetime import timedelta, datetime |
5 | | -from multiprocessing.pool import ThreadPool |
| 5 | +from concurrent.futures import ThreadPoolExecutor |
6 | 6 | from functools import partial |
7 | 7 | from typing import Optional, assert_never |
8 | 8 | from urllib3.exceptions import MaxRetryError |
@@ -282,8 +282,8 @@ def import_recent_matches( |
282 | 282 | if len(jobs) == 1: |
283 | 283 | pool_match_import(*jobs[0], close_connections=False) |
284 | 284 | else: |
285 | | - with ThreadPool(processes=min(10, len(jobs))) as pool: |
286 | | - pool.starmap(pool_match_import, jobs) |
| 285 | + with ThreadPoolExecutor(max_workers=min(10, len(jobs))) as executor: |
| 286 | + executor.map(lambda args: pool_match_import(*args), jobs) |
287 | 287 | logger.info( |
288 | 288 | f"ThreadPool match import: {time.perf_counter() - start_time}" |
289 | 289 | ) |
@@ -746,14 +746,13 @@ def get_player_ranks(summoner_list, threshold_days=1, sync=True): |
746 | 746 | for x in jobs: |
747 | 747 | pt.import_positions(*x) |
748 | 748 | else: |
749 | | - with ThreadPool(processes=10) as pool: |
750 | | - |
| 749 | + with ThreadPoolExecutor(max_workers=10) as executor: |
751 | 750 | def pool_position_import(a, b): |
752 | 751 | pt.import_positions(a, b) |
753 | 752 | connections.close_all() |
754 | 753 |
|
755 | 754 | start_time = time.perf_counter() |
756 | | - pool.starmap(pool_position_import, jobs) |
| 755 | + executor.map(lambda args: pool_position_import(*args), jobs) |
757 | 756 | logger.info( |
758 | 757 | f"ThreadPool positions import: {time.perf_counter() - start_time}" |
759 | 758 | ) |
|
0 commit comments