Skip to content

Commit

Permalink
Remove superfluous try-except clause
Browse files Browse the repository at this point in the history
  • Loading branch information
NPodlozhniy committed Jan 16, 2023
1 parent 0e7a4b1 commit 076ca10
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,21 @@ def get_reality(wks_name, *kwargs) -> list:
row_names=False,
credentials=credentials)
return [str(x) for x in df.values[0]]

# Threading to request concurrently`
with ThreadPoolExecutor(max_workers=8) as pool:
future_expectation = {}
future_reality = {}
for wks_name in wks_names(button):
try:
future_expectation[wks_name] = pool.submit(get_expectation, (wks_name))
except:
pass
future_reality[wks_name] = pool.submit(get_reality, (wks_name))

ref_dict[wks_name] = pool.submit(get_expectation, (wks_name))
fact_dict[wks_name] = pool.submit(get_reality, (wks_name))

# get results from threads
try:
ref_dict = {wks_name: task.result() for wks_name, task in future_expectation.items()}
fact_dict = {wks_name: task.result() for wks_name, task in future_reality.items()}
except:
pass
for wks_name in wks_names(button):
try:
ref_dict[wks_name] = ref_dict[wks_name].result()
except Exception as e:
print(e, flush=True)
finally:
fact_dict[wks_name] = fact_dict[wks_name].result()

text = f"Hello, dear colleague! \n\n Statistics for yesterday by {button}: \n" + \
'\n'.join([f" - {key}" + \
Expand Down

0 comments on commit 076ca10

Please sign in to comment.