Skip to content

Commit ce57f72

Browse files
committed
Share event handler throughout controller instance
1 parent 2173e2e commit ce57f72

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/benchbot_robot_controller.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ def __init__(self, port=10000, auto_start=True):
228228
self.robot_address = 'http://0.0.0.0:' + str(port)
229229

230230
self._auto_start = auto_start
231-
232231
self.config = None
233232
self.config_valid = False
234233

@@ -239,6 +238,10 @@ def __init__(self, port=10000, auto_start=True):
239238

240239
self.instance = None
241240

241+
self.evt = event.Event()
242+
for s in [signal.SIGINT, signal.SIGQUIT, signal.SIGTERM]:
243+
signal.signal(s, lambda n, frame: self.evt.set())
244+
242245
self.wipe()
243246

244247
@staticmethod
@@ -471,29 +474,26 @@ def __selected_env():
471474
# Configure our server
472475
robot_server = pywsgi.WSGIServer(
473476
re.split('http[s]?://', self.robot_address)[-1], robot_flask)
474-
evt = event.Event()
475-
for s in [signal.SIGINT, signal.SIGQUIT, signal.SIGTERM]:
476-
signal.signal(s, lambda n, frame: evt.set())
477477

478478
# Run the server & start the real robot controller
479479
robot_server.start()
480480
print("\nRobot controller is now available @ '%s' ..." %
481481
self.robot_address)
482482
print("Waiting to receive valid config data...")
483483
while not self.config_valid:
484-
if evt.wait(0.1):
484+
if self.evt.wait(0.1):
485485
break
486486

487487
if self._auto_start and self.config_valid:
488488
print("Starting the requested real robot ROS stack ... ",
489489
end="")
490490
sys.stdout.flush()
491-
self.start(events=evt)
491+
self.start()
492492
print("Done")
493493

494494
# Wait until we get an exit signal or crash, then shut down gracefully
495495
while self.instance.health_check():
496-
if evt.wait(0.1):
496+
if self.evt.wait(0.1):
497497
break
498498
print("\nShutting down the real robot ROS stack & exiting ...")
499499
robot_server.stop()
@@ -535,7 +535,7 @@ def set_config(self, config):
535535
# TODO proper checks...
536536
self.config_valid = True
537537

538-
def start(self, events=None):
538+
def start(self):
539539
self.state = {
540540
k: v for k, v in self.state.items() if k in DEFAULT_STATE
541541
}
@@ -546,7 +546,7 @@ def start(self, events=None):
546546
for c in self.connections.values()
547547
if c['type'] == CONN_ROS_TO_API and c['ros'] != None
548548
],
549-
events=events)
549+
events=self.evt)
550550
self.instance.start()
551551

552552
def stop(self):

0 commit comments

Comments
 (0)