From 8d40759415d7173d85e0f7cee516a79fbbae7dbf Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Mon, 23 Jun 2025 01:20:24 -0700 Subject: [PATCH 1/3] better handle tigers_autoref proc - improve exiting speed - properly handle the dangling thread --- .../binary_context_managers/tigers_autoref.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/software/thunderscope/binary_context_managers/tigers_autoref.py b/src/software/thunderscope/binary_context_managers/tigers_autoref.py index efaae73314..4c8bca4f19 100644 --- a/src/software/thunderscope/binary_context_managers/tigers_autoref.py +++ b/src/software/thunderscope/binary_context_managers/tigers_autoref.py @@ -220,7 +220,9 @@ def _forward_to_gamecontroller( def _start_autoref(self) -> None: """Starts the TigersAutoref binary.""" - autoref_cmd = "software/autoref/run_autoref" + env = os.environ.copy() + env["JAVA_HOME"] = "/opt/tbotspython/bin/jdk" + autoref_cmd = "/opt/tbotspython/autoReferee/bin/autoReferee -a" if not self.show_gui: autoref_cmd += " -hl" @@ -231,7 +233,7 @@ def _start_autoref(self) -> None: if self.suppress_logs: with open(os.devnull, "w") as fp: self.tigers_autoref_proc = Popen( - autoref_cmd.split(" "), stdout=fp, stderr=fp + autoref_cmd.split(" "), stdout=fp, stderr=fp, env=env ) else: self.tigers_autoref_proc = Popen(autoref_cmd.split(" ")) @@ -246,13 +248,12 @@ def setup_ssl_wrapper_packets(self, autoref_proto_unix_io: ProtoUnixIO) -> None: autoref_proto_unix_io.register_observer(Referee, self.referee_buffer) def __exit__(self, type, value, traceback) -> None: + self.end_autoref = True if self.tigers_autoref_proc: self.tigers_autoref_proc.terminate() self.tigers_autoref_proc.wait() self.auto_ref_proc_thread.join() - - self.end_autoref = True self.auto_ref_wrapper_thread.join() logging.info("[TigersAutoref] Process exited") From 047d64b46bb28df50ccf408bc839ad402fb25c2c Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Mon, 23 Jun 2025 17:08:33 -0700 Subject: [PATCH 2/3] address comments --- .../binary_context_managers/tigers_autoref.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/software/thunderscope/binary_context_managers/tigers_autoref.py b/src/software/thunderscope/binary_context_managers/tigers_autoref.py index 4c8bca4f19..96a59e9903 100644 --- a/src/software/thunderscope/binary_context_managers/tigers_autoref.py +++ b/src/software/thunderscope/binary_context_managers/tigers_autoref.py @@ -39,6 +39,9 @@ class TigersAutoref(TimeProvider): BUFFER_TIMEOUT = 10 NEXT_PACKET_DELAY = 1.0 / 30 # 30 Hz + AUTOREF_DIR = "/opt/tbotspython/autoReferee" + AUTOREF_JAVA_HOME = "/opt/tbotspython/bin/jdk" + def __init__( self, gc: Gamecontroller, @@ -221,9 +224,9 @@ def _forward_to_gamecontroller( def _start_autoref(self) -> None: """Starts the TigersAutoref binary.""" env = os.environ.copy() - env["JAVA_HOME"] = "/opt/tbotspython/bin/jdk" - autoref_cmd = "/opt/tbotspython/autoReferee/bin/autoReferee -a" + env["JAVA_HOME"] = self.AUTOREF_JAVA_HOME + autoref_cmd = "bin/autoReferee -a" if not self.show_gui: autoref_cmd += " -hl" @@ -233,10 +236,10 @@ def _start_autoref(self) -> None: if self.suppress_logs: with open(os.devnull, "w") as fp: self.tigers_autoref_proc = Popen( - autoref_cmd.split(" "), stdout=fp, stderr=fp, env=env + autoref_cmd.split(" "), stdout=fp, stderr=fp, env=env, cwd=self.AUTOREF_DIR ) else: - self.tigers_autoref_proc = Popen(autoref_cmd.split(" ")) + self.tigers_autoref_proc = Popen(autoref_cmd.split(" "), env=env, cwd=self.AUTOREF_DIR) def setup_ssl_wrapper_packets(self, autoref_proto_unix_io: ProtoUnixIO) -> None: """Registers as an observer of TrackerWrapperPackets from the Simulator, so that they can be forwarded to the From 172c3ac01c7c11f2f7dbce198c9a715a7f0d1d35 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 24 Jun 2025 00:21:09 +0000 Subject: [PATCH 3/3] [pre-commit.ci lite] apply automatic fixes --- .../binary_context_managers/tigers_autoref.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/software/thunderscope/binary_context_managers/tigers_autoref.py b/src/software/thunderscope/binary_context_managers/tigers_autoref.py index 96a59e9903..ed3029746a 100644 --- a/src/software/thunderscope/binary_context_managers/tigers_autoref.py +++ b/src/software/thunderscope/binary_context_managers/tigers_autoref.py @@ -236,10 +236,16 @@ def _start_autoref(self) -> None: if self.suppress_logs: with open(os.devnull, "w") as fp: self.tigers_autoref_proc = Popen( - autoref_cmd.split(" "), stdout=fp, stderr=fp, env=env, cwd=self.AUTOREF_DIR + autoref_cmd.split(" "), + stdout=fp, + stderr=fp, + env=env, + cwd=self.AUTOREF_DIR, ) else: - self.tigers_autoref_proc = Popen(autoref_cmd.split(" "), env=env, cwd=self.AUTOREF_DIR) + self.tigers_autoref_proc = Popen( + autoref_cmd.split(" "), env=env, cwd=self.AUTOREF_DIR + ) def setup_ssl_wrapper_packets(self, autoref_proto_unix_io: ProtoUnixIO) -> None: """Registers as an observer of TrackerWrapperPackets from the Simulator, so that they can be forwarded to the