Exemplo n.º 1
0
    def __init__(self, server, useSessionSweeper=True):
        """Called only by `AppServer`, sets up the Application."""

        self._server = server
        self._serverSidePath = server.serverSidePath()

        self._imp = server._imp  # the import manager

        ConfigurableForServerSidePath.__init__(self)

        print 'Initializing Application...'
        print 'Current directory:', os.getcwd()

        if self.setting('PrintConfigAtStartUp'):
            self.printConfig()

        self.initVersions()
        self.initErrorPage()

        self._shutDownHandlers = []

        # Initialize task manager:
        if self._server.isPersistent():
            from TaskKit.Scheduler import Scheduler
            self._taskManager = Scheduler(
                daemon=True, exceptionHandler=self.handleException)
            self._taskManager.start()
        else:
            self._taskManager = None

        # Define this before initializing URLParser, so that contexts have a
        # chance to override this. Also be sure to define it before loading the
        # sessions, in case the loading of the sessions causes an exception.
        self._exceptionHandlerClass = ExceptionHandler

        self.makeDirs()
        self.initSessions()

        URLParser.initApp(self)
        self._rootURLParser = URLParser.ContextParser(self)

        if useSessionSweeper:
            self.startSessionSweeper()
Exemplo n.º 2
0
def main():
    from time import localtime
    scheduler = Scheduler()
    scheduler.start()
    scheduler.addPeriodicAction(time(), 1, SimpleTask(), 'SimpleTask1')
    scheduler.addTimedAction(time() + 3, SimpleTask(), 'SimpleTask2')
    scheduler.addActionOnDemand(LongTask(), 'LongTask')
    scheduler.addDailyAction(
        localtime(time())[3],
        localtime(time())[4] + 1, SimpleTask(), "DailyTask")
    sleep(5)
    print "Demanding LongTask"
    scheduler.runTaskNow('LongTask')
    sleep(1)
    #	print "Stopping LongTask"
    #	scheduler.stopTask("LongTask")
    sleep(2)
    #	print "Deleting 'SimpleTask1'"
    #	scheduler.unregisterTask("SimpleTask1")
    sleep(4)
    print "Calling stop"
    scheduler.stop()
    ##	sleep(2)
    print "Test Complete"
Exemplo n.º 3
0
def main():
    scheduler = Scheduler()
    scheduler.start()
    scheduler.addPeriodicAction(time(), 1, SimpleTask(), 'SimpleTask1')
    scheduler.addTimedAction(time()+3, SimpleTask(), 'SimpleTask2')
    scheduler.addActionOnDemand(LongTask(), 'LongTask')
    sleep(4)
    print "Demanding 'LongTask'"
    scheduler.runTaskNow('LongTask')
    sleep(1)
    print "Stopping 'LongTask'"
    scheduler.stopTask('LongTask')
    sleep(2)
    print "Deleting 'SimpleTask1'"
    scheduler.unregisterTask('SimpleTask1')
    sleep(2)
    print "Waiting one minute for 'DailyTask'"
    scheduler.addDailyAction(
        localtime()[3], localtime()[4]+1, SimpleTask(), "DailyTask")
    sleep(62)
    print "Calling stop"
    scheduler.stop()
    sleep(2)
    print "Test Complete"
Exemplo n.º 4
0
 def setUp(self):
     from TaskKit.Scheduler import Scheduler
     self.scheduler = Scheduler()
Exemplo n.º 5
0
 def setUp(self):
     self._scheduler = Scheduler()
Exemplo n.º 6
0
    def __init__(self, path=None, settings=None, development=None):
        """Sets up the Application.

        You can specify the path of the application working directory,
        a dictionary of settings to override in the configuration,
        and whether the application should run in development mode.
        """
        ConfigurableForServerSidePath.__init__(self)
        if path is None:
            path = os.getcwd()
        self._serverSidePath = os.path.abspath(path)
        self._webwarePath = os.path.abspath(os.path.dirname(__file__))

        if not os.path.isfile(self.configFilename()):
            print("ERROR: The application cannot be started:")
            print(f"Configuration file {self.configFilename()} not found.")
            raise RuntimeError('Configuration file not found')

        if development is None:
            development = bool(os.environ.get('WEBWARE_DEVELOPMENT'))
        self._development = development

        self.initVersions()

        self._shutDownHandlers = []
        self._plugIns = {}
        self._requestID = 0

        self._imp = ImportManager()

        appConfig = self.config()  # get and cache the configuration
        if settings:
            appConfig.update(settings)

        self._verbose = self.setting('Verbose')
        if self._verbose:
            self._silentURIs = self.setting('SilentURIs')
            if self._silentURIs:
                import re
                self._silentURIs = re.compile(self._silentURIs)
        else:
            self._silentURIs = None
        self._outputEncoding = self.setting('OutputEncoding')
        self._responseBufferSize = self.setting('ResponseBufferSize')
        self._wsgiWrite = self.setting('WSGIWrite')
        if self.setting('CheckInterval') is not None:
            sys.setswitchinterval(self.setting('CheckInterval'))

        logFilename = self.setting('AppLogFilename')
        if logFilename:
            sys.stderr = sys.stdout = open(logFilename, 'a', buffering=1)

        self.initErrorPage()
        self.printStartUpMessage()

        # Initialize task manager:
        if self.setting('RunTasks'):
            self._taskManager = Scheduler(
                daemon=True, exceptionHandler=self.handleException)
            self._taskManager.start()
        else:
            self._taskManager = None

        # Define this before initializing URLParser, so that contexts have a
        # chance to override this. Also be sure to define it before loading the
        # sessions, in case the loading of the sessions causes an exception.
        self._exceptionHandlerClass = ExceptionHandler

        self.makeDirs()
        self.initSessions()

        URLParser.initApp(self)
        self._rootURLParser = URLParser.ContextParser(self)

        self._startTime = time()

        if self.setting('UseSessionSweeper'):
            self.startSessionSweeper()

        self._plugInLoader = None
        self.loadPlugIns()

        self._needsShutDown = [True]
        atexit.register(self.shutDown)
        self._sigTerm = signal.signal(signal.SIGTERM, self.sigTerm)
        try:
            self._sigHup = signal.signal(signal.SIGHUP, self.sigTerm)
        except AttributeError:
            pass  # SIGHUP does not exist on Windows