From 909efef6af6d8d396ea9c8e1122455231a062682 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Fri, 14 Feb 2020 17:31:27 -0800 Subject: [PATCH] Fix waiting for unkillable process. Fixes #1087 (#1099) * Fix waiting for unkillable process. Fixes #1087 * Add bugfix to release notes * Don't pass in exitcode --- RELEASES.md | 1 + selfdrive/manager.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 6a8211ac5..514b3ee02 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -3,6 +3,7 @@ Version 0.7.3 (2020-xx-xx) * Support for 2020 Highlander thanks to che220! * Support for 2018 Lexus NX 300h thanks to kengggg! * Speed up ECU firmware query + * Fix bug where manager would sometimes hang after shutting down the car Version 0.7.2 (2020-02-07) ======================== diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 85f56639f..88b1b84ae 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -289,6 +289,15 @@ def prepare_managed_process(p): subprocess.check_call(["make", "clean"], cwd=os.path.join(BASEDIR, proc[0])) subprocess.check_call(["make", "-j4"], cwd=os.path.join(BASEDIR, proc[0])) + +def join_process(process, timeout): + # Process().join(timeout) will hang due to a python 3 bug: https://bugs.python.org/issue28382 + # We have to poll the exitcode instead + t = time.time() + while time.time() - t < timeout and process.exitcode is None: + time.sleep(0.001) + + def kill_managed_process(name): if name not in running or name not in managed_processes: return @@ -302,18 +311,12 @@ def kill_managed_process(name): else: running[name].terminate() - # Process().join(timeout) will hang due to a python 3 bug: https://bugs.python.org/issue28382 - # We have to poll the exitcode instead - # running[name].join(5.0) - - t = time.time() - while time.time() - t < 5 and running[name].exitcode is None: - time.sleep(0.001) + join_process(running[name], 5) if running[name].exitcode is None: if name in unkillable_processes: cloudlog.critical("unkillable process %s failed to exit! rebooting in 15 if it doesn't die" % name) - running[name].join(15.0) + join_process(running[name], 15) if running[name].exitcode is None: cloudlog.critical("FORCE REBOOTING PHONE!") os.system("date >> /sdcard/unkillable_reboot")