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!!