Skip to content

Commit 5bc6438

Browse files
committed
Use a while loop instead of a fixed wait
1 parent 3c72ed5 commit 5bc6438

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

ur_robot_driver/test/test_common.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,16 @@ def start_robot(self):
246246
time.sleep(1)
247247

248248
robot_mode = self.get_robot_mode()
249-
self._check_call(robot_mode)
250-
if robot_mode.robot_mode.mode != RobotMode.RUNNING:
251-
raise Exception(
252-
f"Incorrect robot mode: Expected {RobotMode.RUNNING}, got {robot_mode.robot_mode.mode}"
253-
)
254-
255-
self._check_call(self.stop())
249+
start_time = time.time()
250+
while time.time() - start_time < 10:
251+
self._check_call(robot_mode)
252+
if robot_mode.robot_mode.mode == RobotMode.RUNNING:
253+
self._check_call(self.stop())
254+
return
255+
time.sleep(0.1)
256+
raise Exception(
257+
f"Incorrect robot mode: Expected {RobotMode.RUNNING}, got {robot_mode.robot_mode.mode}"
258+
)
256259

257260
def _check_call(self, result):
258261
if not result.success:

0 commit comments

Comments
 (0)