-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
26 lines (24 loc) · 893 Bytes
/
Copy pathutils.py
File metadata and controls
26 lines (24 loc) · 893 Bytes
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
import time
import functools
import random
def retry_network_ops(retries=3, backoff=0.5, exceptions=(Exception,)):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
attempts = 0
while attempts < retries:
try:
return func(*args, **kwargs)
except exceptions as e:
attempts += 1
if attempts >= retries:
raise e
wait_time = backoff * (2 ** (attempts - 1)) + (random.random() * 0.1)
time.sleep(wait_time)
return wrapper
return decorator
def execute_game_packet(packet_data):
# Simulate volatile network state
if random.random() < 0.7:
raise ConnectionError("Server lag spike detected")
return f"Packet {packet_data} delivered successfully"