bibibi12345 commited on
Commit
421e7e4
·
1 Parent(s): baebc75

proxy pool race condition fixed

Browse files
Files changed (1) hide show
  1. freeplay2api.py +12 -13
freeplay2api.py CHANGED
@@ -167,7 +167,7 @@ class FreeplayClient:
167
  "referer": "https://app.freeplay.ai/signup",
168
  }
169
 
170
- max_retries = 5
171
  for attempt in range(max_retries):
172
  proxy_info = None
173
  try:
@@ -224,8 +224,6 @@ class FreeplayClient:
224
  except Exception as e:
225
  logging.error(f"An unexpected error occurred during registration on attempt {attempt + 1}/{max_retries}: {e}. Retrying...")
226
 
227
- time.sleep(1)
228
-
229
  logging.error("Failed to register a new account after multiple retries.")
230
  return None
231
 
@@ -364,16 +362,17 @@ class KeyMaintainer(threading.Thread):
364
  ]
365
  needed = self.config["ACTIVE_KEY_THRESHOLD"] - len(healthy_accounts)
366
 
367
- if needed > 0:
368
- logging.info(f"Healthy accounts ({len(healthy_accounts)}) below threshold. Need to register {needed} new accounts.")
369
- with concurrent.futures.ThreadPoolExecutor(max_workers=self.config["REGISTRATION_CONCURRENCY"]) as executor:
370
- futures = [executor.submit(self.client.register) for _ in range(needed)]
371
- for future in concurrent.futures.as_completed(futures):
372
- new_account = future.result()
373
- if new_account:
374
- self.manager.add_account(new_account)
375
- else:
376
- logging.info(f"Sufficient healthy accounts ({len(healthy_accounts)}).")
 
377
 
378
  except Exception as e:
379
  logging.error(f"Error in KeyMaintainer cycle: {e}")
 
167
  "referer": "https://app.freeplay.ai/signup",
168
  }
169
 
170
+ max_retries = 10
171
  for attempt in range(max_retries):
172
  proxy_info = None
173
  try:
 
224
  except Exception as e:
225
  logging.error(f"An unexpected error occurred during registration on attempt {attempt + 1}/{max_retries}: {e}. Retrying...")
226
 
 
 
227
  logging.error("Failed to register a new account after multiple retries.")
228
  return None
229
 
 
362
  ]
363
  needed = self.config["ACTIVE_KEY_THRESHOLD"] - len(healthy_accounts)
364
 
365
+ while needed > 0:
366
+ logging.info(f"Healthy accounts ({len(healthy_accounts)}) below threshold. Need to register {needed} new accounts. Retrying immediately.")
367
+ new_account = self.client.register()
368
+ if new_account:
369
+ self.manager.add_account(new_account)
370
+
371
+ healthy_accounts = [
372
+ acc for acc in self.manager.get_all_accounts()
373
+ if acc.get("balance", 0) > self.config["LOW_BALANCE_THRESHOLD"]
374
+ ]
375
+ needed = self.config["ACTIVE_KEY_THRESHOLD"] - len(healthy_accounts)
376
 
377
  except Exception as e:
378
  logging.error(f"Error in KeyMaintainer cycle: {e}")