You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not really sure where you need async operations, but if it helps I worked a little with the new NHL API and used concurrency feature of python to get all landing data for batch games.
import concurrent.futures
def processGameLanding(game):
game_id = game['id']
try:
getNHLGameLanding(game_id)
except Exception as landing_error:
print(f"Error retrieving Game Landing for game {game_id}: {landing_error}")
print(f'Completed game: {game_id}')
def getAllLanding():
num_threads = 100
schedule_file_names = get_file_names('../data/nhl-v2/schedule')
for schedule_file_name in schedule_file_names:
print(f'Schedule File: {schedule_file_name}')
games = readJSON(f'../data/nhl-v2/schedule/{schedule_file_name}')['games']
# Create a ThreadPoolExecutor <---- This Part!
with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:
# Submit tasks to the executor and get a list of futures
futures = [executor.submit(processGameLanding, game) for game in games]
# Use as_completed to iterate over completed futures
for future in concurrent.futures.as_completed(futures):
try:
future.result() # Retrieve the result or raise an exception if an error occurred
except Exception as e:
print(f"An error occurred: {e}")
I am thinking about updating this to support async operations. If anyone has any feedback, for or against, I would love to hear it.
The text was updated successfully, but these errors were encountered: