Skip to content

Commit

Permalink
Update Palworld.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Mar 13, 2024
1 parent 90e67b4 commit 4da37bf
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions protocols/Palworld.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait
from datetime import datetime, timezone
from pymongo import UpdateOne
from tqdm import tqdm
Expand Down Expand Up @@ -63,13 +64,21 @@ def _fetch_until_empty(self):
servers = []
pbar = tqdm(total=1, desc=f'[{self.key}] Fetch Page')

while pbar.n < pbar.total:
if server_list := self._fetch_page(pbar.total):
servers.extend(server_list)
pbar.total += 1
with ThreadPoolExecutor() as executor:
futures = {executor.submit(self._fetch_page, pbar.total)}

pbar.update(1)
pbar.refresh()
while futures:
done, futures = wait(futures, return_when=FIRST_COMPLETED)

for future in done:
pbar.update(1)

if server_list := future.result():
pbar.total += 1
futures.add(executor.submit(self._fetch_page, pbar.total))
servers.extend(server_list)

pbar.refresh()

return servers

Expand Down

0 comments on commit 4da37bf

Please sign in to comment.