Changeset 2ac545d


Ignore:
Timestamp:
04/27/2009 06:50:41 PM (16 years ago)
Author:
Andrew Resch <andrewresch@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
8582915
Parents:
725198
Message:

Clean-up signal handling since twisted.reactor handles it now

Location:
deluge
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • deluge/core/daemon.py

    r725198 r2ac545d  
    2222#       Boston, MA    02110-1301, USA.
    2323#
    24 
    25 import signal
    2624
    2725import gettext
     
    5250            log.error("Unable to initialize gettext/locale: %s", e)
    5351
    54         # Setup signals
    55         signal.signal(signal.SIGINT, self.shutdown)
    56         signal.signal(signal.SIGTERM, self.shutdown)
    57         if not deluge.common.windows_check():
    58             signal.signal(signal.SIGHUP, self.shutdown)
    59         else:
     52        # Twisted catches signals to terminate, so just have it call the shutdown
     53        # method.
     54        reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
     55
     56        # Catch some Windows specific signals
     57        if deluge.common.windows_check():
    6058            from win32api import SetConsoleCtrlHandler
    6159            from win32con import CTRL_CLOSE_EVENT
  • deluge/ui/gtkui/gtkui.py

    r725198 r2ac545d  
    3434import locale
    3535import pkg_resources
    36 import signal
    3736import gtk, gtk.glade
    3837
     
    133132        except:
    134133            pass
    135         signal.signal(signal.SIGINT, self.shutdown)
    136         signal.signal(signal.SIGTERM, self.shutdown)
     134
     135        # Twisted catches signals to terminate, so just have it call the shutdown
     136        # method.
     137        reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
    137138
    138139        if deluge.common.windows_check():
  • deluge/ui/web/server.py

    r725198 r2ac545d  
    2727import locale
    2828import shutil
    29 import signal
    30 import signal
    3129import urllib
    3230import gettext
     
    9391    available as Deluge.Config.
    9492    """
    95    
     93
    9694    def render(self, request):
    9795        return """Deluge = {
     
    111109    Twisted Web resource to handle file uploads
    112110    """
    113    
     111
    114112    def render(self, request):
    115113        """
     
    117115        each on a new line.
    118116        """
    119        
     117
    120118        # Block all other HTTP methods.
    121119        if request.method != "POST":
    122120            request.setResponseCode(http.NOT_ALLOWED)
    123121            return ""
    124        
     122
    125123        if "file" not in request.args:
    126124            request.setResponseCode(http.OK)
    127125            return ""
    128        
     126
    129127        tempdir = os.path.join(tempfile.gettempdir(), "delugeweb")
    130128        if not os.path.isdir(tempdir):
     
    146144        request.render_file = path
    147145        return self
    148    
     146
    149147    def render(self, request):
    150148        if not hasattr(request, "render_file"):
     
    160158class Tracker(resource.Resource):
    161159    tracker_icons = TrackerIcons()
    162    
     160
    163161    def getChild(self, path, request):
    164162        request.tracker_name = path
    165163        return self
    166    
     164
    167165    def render(self, request):
    168166        headers = {}
     
    186184        request.country = path
    187185        return self
    188    
     186
    189187    def render(self, request):
    190188        headers = {}
     
    204202
    205203class LookupResource(resource.Resource, component.Component):
    206    
    207     def __init__(self, name, *directories):       
     204
     205    def __init__(self, name, *directories):
    208206        resource.Resource.__init__(self)
    209207        component.Component.__init__(self, name)
    210208        self.__directories = directories
    211    
     209
    212210    @property
    213211    def directories(self):
    214212        return self.__directories
    215    
     213
    216214    def getChild(self, path, request):
    217215        request.path = path
    218216        return self
    219    
     217
    220218    def render(self, request):
    221219        log.debug("Requested path: '%s'", request.path)
     
    232230class TopLevel(resource.Resource):
    233231    addSlash = True
    234    
     232
    235233    __stylesheets = [
    236234        "/css/ext-all.css",
     
    238236        "/css/deluge.css"
    239237    ]
    240    
     238
    241239    __scripts = [
    242240        "/js/ext-base.js",
     
    247245        "/js/deluge-yc.js"
    248246    ]
    249    
     247
    250248    __debug_scripts = [
    251249        "/js/ext-base.js",
     
    289287        "/js/Deluge.UI.js"
    290288    ]
    291    
     289
    292290    def __init__(self):
    293291        resource.Resource.__init__(self)
     
    304302        self.putChild("themes", static.File(rpath("themes")))
    305303        self.putChild("tracker", Tracker())
    306        
     304
    307305        theme = component.get("DelugeWeb").config["theme"]
    308306        self.__stylesheets.append("/css/xtheme-%s.css" % theme)
     
    311309    def scripts(self):
    312310        return self.__scripts
    313    
     311
    314312    @property
    315313    def debug_scripts(self):
    316314        return self.__debug_scripts
    317    
     315
    318316    @property
    319317    def stylesheets(self):
    320318        return self.__stylesheets
    321    
     319
    322320    def getChild(self, path, request):
    323321        if path == "":
     
    331329        else:
    332330            scripts = self.scripts[:]
    333            
     331
    334332        template = Template(filename=rpath("index.html"))
    335333        request.setHeader("content-type", "text/html; charset=utf-8")
     
    337335
    338336class DelugeWeb(component.Component):
    339    
     337
    340338    def __init__(self):
    341339        super(DelugeWeb, self).__init__("DelugeWeb")
    342340        self.config = ConfigManager("web.conf", CONFIG_DEFAULTS)
    343        
     341
    344342        self.top_level = TopLevel()
    345343        self.site = server.Site(self.top_level)
    346344        self.port = self.config["port"]
    347345        self.web_api = WebApi()
    348        
     346
    349347        # Since twisted assigns itself all the signals may as well make
    350348        # use of it.
     
    363361                    return 1
    364362            SetConsoleCtrlHandler(win_handler)
    365        
     363
    366364        # Initalize the plugins
    367365        self.plugins = PluginManager()
Note: See TracChangeset for help on using the changeset viewer.