from flup.server.fcgi import WSGIServer
import time
from os.path import getmtime

class RestartingServer(WSGIServer):
    """A variant on WSGIServer that exits if we've been modified, to
    allow Apache to restart us."""

    def __init__(self, app, file):
        WSGIServer.__init__(self, app)
        self.file = file
        self.starttime = time.time()
    
    def _mainloopPeriodic(self):
        WSGIServer._mainloopPeriodic(self)
        
        mod = getmtime(self.file)
        if mod > self.starttime:
            self._keepGoing = False
