From 21506dd5aefc1906ba8e4acad6554753874b2473 Mon Sep 17 00:00:00 2001 From: Doadin <tbkizle@gmail.com> Date: Mon, 7 Jul 2014 06:50:50 -0400 Subject: [PATCH] Pylint daemon --- deluge/core/daemon.py | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/deluge/core/daemon.py b/deluge/core/daemon.py index 93aba8b..f280d1b 100644 --- a/deluge/core/daemon.py +++ b/deluge/core/daemon.py @@ -17,9 +17,9 @@ # # You should have received a copy of the GNU General Public License # along with deluge. If not, write to: -# The Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor -# Boston, MA 02110-1301, USA. +# The Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. # # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the OpenSSL @@ -33,7 +33,7 @@ # import os import logging -from twisted.internet import reactor +from twisted.internet.interfaces import IReactorCore import deluge.component as component from deluge.configmanager import get_config_dir @@ -50,7 +50,7 @@ def check_running_daemon(pid_file): - """Check for another running instance of the daemon using the same pid file""" + """Check for another running instance """ if os.path.isfile(pid_file): # Get the PID and the port of the supposedly running daemon with open(pid_file) as _file: @@ -61,11 +61,13 @@ def check_running_daemon(pid_file): pid, port = None, None def process_running(pid): + """check for running process""" if windows_check(): from win32process import EnumProcesses return pid in EnumProcesses() else: - # We can just use os.kill on UNIX to test if the process is running + # We can just use os.kill on UNIX to + # test if the process is running try: os.kill(pid, 0) except OSError: @@ -74,7 +76,8 @@ def process_running(pid): return True if pid is not None and process_running(pid): - # Ensure it's a deluged process by trying to open a socket to it's port. + # Ensure it's a deluged process by + # trying to open a socket to it's port. import socket _socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: @@ -85,10 +88,12 @@ def process_running(pid): else: # This is a deluged! _socket.close() - raise DaemonRunningError("Deluge daemon already running with this config directory!") + raise DaemonRunningError("Deluge daemon already running \ + with this config directory!") class Daemon(object): + """start daemon class""" def __init__(self, options=None, args=None, classic=False): log.info("Deluge daemon %s", get_version()) log.debug("options: %s", options) @@ -97,20 +102,24 @@ def __init__(self, options=None, args=None, classic=False): pid_file = get_config_dir("deluged.pid") check_running_daemon(pid_file) - # Twisted catches signals to terminate, so just have it call the shutdown method. - reactor.addSystemEventTrigger("before", "shutdown", self._shutdown) + # Twisted catches signals to terminate, + # so just have it call the shutdown method. + IReactorCore.addSystemEventTrigger("before", "shutdown", self._shutdown) # Catch some Windows specific signals if windows_check(): def win_handler(ctrl_type): + """windows checks""" log.debug("windows handler ctrl_type: %s", ctrl_type) - if ctrl_type == CTRL_CLOSE_EVENT or ctrl_type == CTRL_SHUTDOWN_EVENT: + if ctrl_type == CTRL_CLOSE_EVENT or \ + ctrl_type == CTRL_SHUTDOWN_EVENT: self._shutdown() return 1 SetConsoleCtrlHandler(win_handler) listen_interface = None - if options and options.listen_interface and is_ip(options.listen_interface): + if options and options.listen_interface \ + and is_ip(options.listen_interface): listen_interface = options.listen_interface # Start the core as a thread and join it until it's done @@ -141,7 +150,8 @@ def win_handler(ctrl_type): if not classic: log.info("Deluge daemon starting...") - # Create pid file to track if deluged is running, also includes the port number. + # Create pid file to track if deluged + # is running, also includes the port number. pid = os.getpid() log.debug("Storing pid %s & port %s in: %s", pid, port, pid_file) with open(pid_file, "wb") as _file: @@ -150,19 +160,22 @@ def win_handler(ctrl_type): component.start() try: - reactor.run() + IReactorCore.run() finally: log.debug("Remove pid file: %s", pid_file) os.remove(pid_file) log.info("Deluge daemon shutdown successfully") @export() - def shutdown(self, *args, **kwargs): + def shutdown(self): + """shutdown requested""" log.debug("Deluge daemon shutdown requested...") - reactor.callLater(0, reactor.stop) + IReactorCore.stop() - def _shutdown(self, *args, **kwargs): - log.info("Deluge daemon shutting down, waiting for components to shutdown...") + def _shutdown(self): + """deluged shutdown process""" + log.info("Deluge daemon shutting down,\ + waiting for components to shutdown...") return component.shutdown() @export() -- 1.9.3