Skip to content

Commit

Permalink
fix(gvm): Properly destroys all variables in the gvm
Browse files Browse the repository at this point in the history
- When exiting the GUI or ending the core/start.py script, now a function will be called to properly delete all variables in the global variable manager
- Improves dealing with threads and spinning nodes (ROS2)
  • Loading branch information
JohannesErnst committed Aug 12, 2024
1 parent 50fc72a commit e12a253
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source/rafcon/core/global_variable_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ def get_all_keys_starting_with(self, start_key):
if g_key and start_key in g_key:
output_list.append(g_key)
return output_list

def destroy_all_variables(self):
""" Deletes all global variables in a loop and then clears access keys and
type dictionary. Is called on shutdown.
"""
for key in list(self.__global_variable_dictionary):
self.delete_variable(key)
self.reset()

logger.debug("All global variables were deleted!")

#########################################################################
# Properties for all class fields that must be observed by gtkmvc3
Expand Down
6 changes: 6 additions & 0 deletions source/rafcon/core/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ def main(optional_args=None):
time.sleep(1)

logger.info("State machine execution finished!")

plugins.run_hook("post_destruction")

# Properly destroy all global variables
gvm = core_singletons.global_variable_manager
gvm.destroy_all_variables()

logging.shutdown()

if user_input.memory_profiling:
Expand Down
4 changes: 4 additions & 0 deletions source/rafcon/gui/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ def stop_gtk():
def post_gui_destruction():
plugins.run_hook("post_destruction")

# Properly destroy all global variables
gvm = core_singletons.global_variable_manager
gvm.destroy_all_variables()

if global_gui_config.get_config_value('AUTO_RECOVERY_LOCK_ENABLED'):
import rafcon.gui.models.auto_backup
rafcon.gui.models.auto_backup.remove_rafcon_instance_lock_file()
Expand Down

0 comments on commit e12a253

Please sign in to comment.