From 82a7b914b64e6add6fd5c349a5149af5adf2febc Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 31 Aug 2017 13:36:46 -0700 Subject: [PATCH] Move control.tried_shutdown to world.shutting_down --- classes.py | 3 +-- coremods/control.py | 7 ++----- world.py | 5 +++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/classes.py b/classes.py index df03bdf..9ab6ccb 100644 --- a/classes.py +++ b/classes.py @@ -26,7 +26,6 @@ except ImportError: from . import world, utils, structures, conf, __version__ from .log import * -from .coremods import control from .utils import ProtocolError # Compatibility with PyLink 1.x ### Internal classes (users, servers, channels) @@ -1265,7 +1264,7 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils): def _log_connection_error(self, *args, **kwargs): # Log connection errors to ERROR unless were shutting down (in which case, # the given text goes to DEBUG). - if self._aborted.is_set() or control.tried_shutdown: + if self._aborted.is_set() or world.shutting_down.is_set(): log.debug(*args, **kwargs) else: log.error(*args, **kwargs) diff --git a/coremods/control.py b/coremods/control.py index 2338b58..38e4870 100644 --- a/coremods/control.py +++ b/coremods/control.py @@ -11,8 +11,6 @@ from pylinkirc import world, utils, conf # Do not import classes, it'll import from pylinkirc.log import log, makeFileLogger, stopFileLoggers, getConsoleLogLevel from . import permissions -tried_shutdown = False - def remove_network(ircobj): """Removes a network object from the pool.""" # Disable autoconnect first by setting the delay negative. @@ -57,12 +55,11 @@ atexit.register(_kill_plugins) def shutdown(irc=None): """Shuts down the Pylink daemon.""" - global tried_shutdown - if tried_shutdown: # We froze on shutdown last time, so immediately abort. + if world.shutting_down.is_set(): # We froze on shutdown last time, so immediately abort. _print_remaining_threads() raise KeyboardInterrupt("Forcing shutdown.") - tried_shutdown = True + world.shutting_down.set() # HACK: run the _kill_plugins trigger with the current IRC object. XXX: We should really consider removing this # argument, since no plugins actually use it to do anything. diff --git a/world.py b/world.py index 6fda5e0..535bbe9 100644 --- a/world.py +++ b/world.py @@ -22,8 +22,13 @@ exttarget_handlers = {} # Trigger to be set when all IRC objects are initially created. started = threading.Event() + +# Global daemon starting time. start_ts = time.time() +# Trigger to set on shutdown. +shutting_down = threading.Event() + # Source address. source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!!