Skip to content

Commit

Permalink
Decided not to wait for threads that are not critical for the rfswarm…
Browse files Browse the repository at this point in the history
… apps (gui-threads sometimes freeze).

Instead exit using os._exit().
Maybe back to joining all threads after implementing eel module.

Issue damies13#288
  • Loading branch information
ArekKuczynski committed Aug 20, 2024
1 parent 330b4e2 commit eaa3fd7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 50 deletions.
13 changes: 6 additions & 7 deletions Tests/Regression/Manager/GUI_Common.robot
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,12 @@ Close Manager GUI macos
END

Stop Agent
${result} = Terminate Process ${process_agent}
# IF '${platform}' == 'windows'
# Evaluate os.kill(${process_agent.pid}, signal.SIGINT) modules=subprocess, os, signal
# ELSE
# Send Signal To Process SIGINT ${process_agent}
# END
${result}= Wait For Process ${process_agent} timeout=30 on_timeout=kill
IF '${platform}' == 'windows' # Send Signal To Process keyword does not work on Windows
${result} = Terminate Process ${process_agent}
ELSE
Send Signal To Process SIGINT ${process_agent}
${result}= Wait For Process ${process_agent} timeout=30 on_timeout=kill
END
Log ${result.stdout}
Log ${result.stderr}
# Should Be Equal As Integers ${result.rc} 0
Expand Down
12 changes: 1 addition & 11 deletions rfswarm_agent/rfswarm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,24 +1975,14 @@ def on_closing(self, _event=None, *args):
self.jobs[jobid]["Thread"].join()

time.sleep(1)
self.debugmsg(3, "Waiting for all threads to be completed")
for thread in threading.enumerate():
if thread is not threading.main_thread() and thread.is_alive():
if thread.name not in ["UpdateAgents"]:
self.debugmsg(9, thread.name, "before")
thread.join(timeout=30)
self.debugmsg(9, thread.name, "after")
if thread.is_alive():
self.debugmsg(9, thread.name, "did not complete in 30s!")

self.debugmsg(2, "Exit")
try:
sys.exit(0)
except SystemExit as e:
try:
remaining_threads = [t for t in threading.enumerate() if t is not threading.main_thread() and t.is_alive()]
if remaining_threads:
self.debugmsg(3, "Failed to gracefully exit RFSwarm-Agent. Forcing immediate exit.")
self.debugmsg(5, "Failed to gracefully exit RFSwarm-Agent. Forcing immediate exit.")
for thread in remaining_threads:
self.debugmsg(9, "Thread name:", thread.name)
os._exit(0)
Expand Down
20 changes: 1 addition & 19 deletions rfswarm_manager/rfswarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2662,14 +2662,6 @@ def on_closing(self, _event=None, *args):
base.keeprunning = False
self.neededagents = 0

try:
if base.updateplanthread.is_alive():
base.debugmsg(9, "Join Update Plan Display")
base.updateplanthread.join(timeout=30)
base.debugmsg(9, "Join Update Plan Display after")
except Exception:
pass

if base.appstarted:
try:
base.debugmsg(0, "Shutdown Agent Manager")
Expand Down Expand Up @@ -2702,24 +2694,14 @@ def on_closing(self, _event=None, *args):
pass

time.sleep(1)
base.debugmsg(3, "Waiting for all threads to be completed")
for thread in threading.enumerate():
if thread is not threading.main_thread() and thread.is_alive():
if thread.name not in ["UpdateAgents"]:
base.debugmsg(9, thread.name, "before")
thread.join(timeout=30)
base.debugmsg(9, thread.name, "after")
if thread.is_alive():
base.debugmsg(9, thread.name, "did not complete in 30s!")

base.debugmsg(2, "Exit")
try:
sys.exit(0)
except SystemExit as e:
try:
remaining_threads = [t for t in threading.enumerate() if t is not threading.main_thread() and t.is_alive()]
if remaining_threads:
base.debugmsg(3, "Failed to gracefully exit RFSwarm-Manager. Forcing immediate exit.")
base.debugmsg(5, "Failed to gracefully exit RFSwarm-Manager. Forcing immediate exit.")
for thread in remaining_threads:
base.debugmsg(9, "Thread name:", thread.name)
os._exit(0)
Expand Down
28 changes: 15 additions & 13 deletions rfswarm_reporter/rfswarm_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2868,22 +2868,24 @@ def on_closing(self, _event=None, *extras):
# base.close_results_db()
base.stop_db()

time.sleep(1)
base.debugmsg(2, "Exit")
for thread in threading.enumerate():
if thread.name != "MainThread":
if thread.is_alive():
base.debugmsg(9, thread.name, "before")
thread.join(timeout=30)
base.debugmsg(9, thread.name, "after")

try:
sys.exit(0)
except Exception as e:
except SystemExit as e:
try:
self.debugmsg(0, "Failed to exit with error:", e)
sys.exit(0)
except Exception:
os._exit(0)
remaining_threads = [t for t in threading.enumerate() if t is not threading.main_thread() and t.is_alive()]
if remaining_threads:
base.debugmsg(5, "Failed to gracefully exit RFSwarm-Reporter. Forcing immediate exit.")
for thread in remaining_threads:
base.debugmsg(9, "Thread name:", thread.name)
os._exit(0)
else:
raise e

except Exception as e:
base.debugmsg(3, "Failed to exit with error:", e)
os._exit(1)

def selectResults(self, resultsfile):
base.debugmsg(5, "resultsfile:", resultsfile)
Expand Down Expand Up @@ -2914,7 +2916,7 @@ def display_message(self, *mesage):
for msg in mesage:
msglst.append(msg)
msgout = " ".join(msglst)
while base.gui is None:
while base.gui is None and base.running:
time.sleep(0.5)
base.gui.updateStatus(msgout)
else:
Expand Down

0 comments on commit eaa3fd7

Please sign in to comment.