3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-05-08 07:37:33 +02:00

control: try a more stable force-shutdown routine

This commit is contained in:
James Lu 2017-02-18 12:19:42 -08:00
parent 050721af5b
commit a3f122fee4

View File

@ -4,11 +4,14 @@ control.py - Implements SHUTDOWN and REHASH functionality.
import signal import signal
import os import os
import threading import threading
import sys
from pylinkirc import world, utils, conf, classes from pylinkirc import world, utils, conf, classes
from pylinkirc.log import log, makeFileLogger, stopFileLoggers, stdoutLogLevel from pylinkirc.log import log, makeFileLogger, stopFileLoggers, stdoutLogLevel
from . import permissions from . import permissions
tried_shutdown = False
def remove_network(ircobj): def remove_network(ircobj):
"""Removes a network object from the pool.""" """Removes a network object from the pool."""
# Disable autoconnect first by setting the delay negative. # Disable autoconnect first by setting the delay negative.
@ -18,6 +21,12 @@ def remove_network(ircobj):
def _shutdown(irc=None): def _shutdown(irc=None):
"""Shuts down the Pylink daemon.""" """Shuts down the Pylink daemon."""
global tried_shutdown
if tried_shutdown: # We froze on shutdown last time, so immediately abort.
sys.exit()
tried_shutdown = True
for name, plugin in world.plugins.items(): for name, plugin in world.plugins.items():
# Before closing connections, tell all plugins to shutdown cleanly first. # Before closing connections, tell all plugins to shutdown cleanly first.
if hasattr(plugin, 'die'): if hasattr(plugin, 'die'):