Skip to content

Commit

Permalink
chore: kill_timer control
Browse files Browse the repository at this point in the history
Prevents atexit issues with python debugger monkey patching.
  • Loading branch information
joamag committed Jan 8, 2024
1 parent 0e12f8c commit 4518de9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

*
* Added support for optional `kill_timer` avoiding `@atexit` issues

### Fixed

Expand Down
20 changes: 13 additions & 7 deletions src/colony/base/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ def load_system(self, mode=None, args=None, callback=None):
# error has occurred or any other value otherwise
return self.return_code

def unload_system(self, thread_safe=True):
def unload_system(self, thread_safe=True, kill_timer=True):
"""
Unloads the plugin system from memory, exiting the system.
A timer is installed to exit the system in a forced way
Expand All @@ -2295,6 +2295,9 @@ def unload_system(self, thread_safe=True):
:type thread_safe: bool
:param thread_safe: If the unloading should use the event mechanism
to provide thread safety.
:type kill_timer: bool
:param kill_timer: If the kill timer should be used to kill the system
in case it gets stuck for longer than the shutdown timeout.
"""

# in case the system initialization is not complete
Expand All @@ -2307,10 +2310,11 @@ def unload_system(self, thread_safe=True):
# creates the kill system timer, to kill the system
# if it hangs in shutdown and starts it so that the
# system will be able to kill itself after a timeout
self.kill_system_timer = threading.Timer(
DEFAULT_UNLOAD_SYSTEM_TIMEOUT, self._kill_system_timeout
)
self.kill_system_timer.start()
if kill_timer:
self.kill_system_timer = threading.Timer(
DEFAULT_UNLOAD_SYSTEM_TIMEOUT, self._kill_system_timeout
)
self.kill_system_timer.start()

# iterates over all the plugin instances running the unload process
# for all of them and according to their set of skill/capabilities
Expand Down Expand Up @@ -2346,8 +2350,10 @@ def unload_system(self, thread_safe=True):
# unloads the thread based plugins
self._unload_thread_plugins()

# cancels the kill system timer
self.kill_system_timer.cancel()
# cancels the kill system timer, in case it has been
# defined (no need to kill the system anymore)
if self.kill_system_timer:
self.kill_system_timer.cancel()

def reload_system(self, thread_safe=True):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/colony_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def unload_system():
# the used resources and killing all the threads
# this should be enough to return the control to
# the embedding process
plugin_manager.unload_system()
plugin_manager.unload_system(kill_timer=False)


class ServerThread(threading.Thread):
Expand Down

0 comments on commit 4518de9

Please sign in to comment.