-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
37 lines (33 loc) · 1.15 KB
/
Copy pathcore.py
File metadata and controls
37 lines (33 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import time
import functools
import random
def gaming_retry(max_attempts=3, backoff=0.5):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
attempts = 0
while attempts < max_attempts:
try:
return func(*args, **kwargs)
except Exception as e:
attempts += 1
if attempts == max_attempts:
raise e
wait_time = backoff * (2 ** (attempts - 1)) + random.uniform(0, 0.1)
time.sleep(wait_time)
return wrapper
return decorator
@gaming_retry(max_attempts=5, backoff=1.0)
def fetch_server_state(endpoint):
# Simulate network instability in game matchmaking
if random.random() < 0.7:
raise ConnectionError("Latency spike detected")
return {"status": "ready", "players": 42}
class GameNetworkClient:
def __init__(self, host):
self.host = host
def execute(self, command):
@gaming_retry(max_attempts=3)
def perform():
return f"Command {command} executed on {self.host}"
return perform()