MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / safe_command

Function safe_command

tests/integration/conftest.py:90–107  ·  view source on GitHub ↗
(func, *args, max_retries=2, **kwargs)

Source from the content-addressed store, hash-verified

88
89 # Helper to retry operations if server disconnected
90 def safe_command(func, *args, max_retries=2, **kwargs):
91 for attempt in range(max_retries):
92 try:
93 return func(*args, **kwargs)
94 except ConnectionError:
95 if attempt < max_retries - 1:
96 # Server might have disconnected us, try to reconnect
97 time.sleep(1.0)
98 try:
99 api_client.disconnect()
100 api_client.connect()
101 except:
102 pass
103 else:
104 # Final attempt failed, ignore
105 pass
106 except Exception:
107 pass
108
109 # Clean up before test
110 safe_command(api_client.disconnect_device)

Callers 1

clean_stateFunction · 0.70

Calls 2

disconnectMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected