Skip to content

Commit

Permalink
Merge pull request #1716 from pupil-labs/shutdown-service-used-port
Browse files Browse the repository at this point in the history
Correctly shutdown Service if port is already in use
  • Loading branch information
papr authored Nov 4, 2019
2 parents 920b124 + c369940 commit 00790a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 14 additions & 9 deletions pupil_src/launchables/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,25 @@ def get_dt():

audio.audio_mode = session_settings.get("audio_mode", audio.default_audio_mode)

ipc_pub.notify({"subject": "service_process.started"})
logger.warning("Process started.")
g_pool.service_should_run = True

# plugins that are loaded based on user settings from previous session
g_pool.plugins = Plugin_List(
g_pool, session_settings.get("loaded_plugins", default_plugins)
)

# NOTE: The Pupil_Remote plugin fails to load when the port is already in use
# and will set this variable to false. Then we should not even start the eye
# processes. Otherwise we would have to wait for their initialization before
# attempting cleanup in Service.
if g_pool.service_should_run:
if session_settings.get("eye1_process_alive", True):
launch_eye_process(1, delay=0.3)
if session_settings.get("eye0_process_alive", True):
launch_eye_process(0, delay=0.0)

def handle_notifications(n):
subject = n["subject"]
if subject == "set_detection_mapping_mode":
Expand Down Expand Up @@ -244,15 +258,6 @@ def handle_notifications(n):
}
)

if session_settings.get("eye1_process_alive", True):
launch_eye_process(1, delay=0.3)
if session_settings.get("eye0_process_alive", True):
launch_eye_process(0, delay=0.0)

ipc_pub.notify({"subject": "service_process.started"})
logger.warning("Process started.")
g_pool.service_should_run = True

# initiate ui update loop
ipc_pub.notify(
{"subject": "service_process.ui.should_update", "initial_delay": 1 / 40}
Expand Down
6 changes: 5 additions & 1 deletion pupil_src/shared_modules/pupil_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ def start_server(self, new_address):
# for service we shut down
if self.g_pool.app == "service":
audio.say("Error: Port already in use.")
self.notify_all({"subject": "service_process.should_stop"})
# NOTE: We don't want a should_stop notification, but a hard termination at
# this point, because Service is still initializing at this point. This way
# we can prevent the eye processes from starting, where otherwise we would
# have to wait for them to be started until we can close them.
self.g_pool.service_should_run = False
return

# for capture we try to bind to a arbitrary port on the first external interface
Expand Down

0 comments on commit 00790a3

Please sign in to comment.