예제 #1
0
    def start(self, params = None, last_return = None):
        """
Start the GLib based main loop in a separate thread.

:param params: Parameter specified
:param last_return: The return value from the last hook called.

:since: v0.2.00
        """

        if (self.mainloop is None): Thread.start(self)
        return last_return
예제 #2
0
    def update_timestamp(self, timestamp = -1):
        """
Update the timestamp for the next "run()" call.

:param timestamp: Externally defined UNIX timestamp of the next scheduled
                  run.

:since: v1.0.0
        """

        if (self._log_handler is not None): self._log_handler.debug("#echo(__FILEPATH__)# -{0!r}.update_timestamp({1})- (#echo(__LINE__)#)", self, timestamp, context = "pas_timed_tasks")

        if (self.timer_active):
            thread = None

            with self.lock:
                # Thread safety
                timeout = -1

                if (self.timer_active):
                    if (timestamp < 0): timestamp = self._next_update_timestamp

                    if (timestamp > 0):
                        timeout = timestamp - time()
                        if (timeout < 0): timeout = 0
                    #
                #

                if (timeout < 0):
                    if (self.timer is not None and self.timer.is_alive()):
                        self.timer.cancel()
                        self.timer_timestamp = -1
                    #
                elif (self.timer_timestamp < 0 or timestamp < self.timer_timestamp):
                    if (self.timer is not None and self.timer.is_alive()): self.timer.cancel()

                    if (timeout > 0):
                        self.timer = Timer(timeout, self.run)
                        self.timer_timestamp = timestamp

                        if (self._log_handler is not None): self._log_handler.debug("{0!r} waits for {1} seconds", self, timeout, context = "pas_timed_tasks")
                        self.timer.start()
                    else:
                        if (self._log_handler is not None): self._log_handler.debug("{0!r} continues with the next step", self, context = "pas_timed_tasks")

                        thread = Thread(target = self.run)
                    #
                #
            #

            if (thread is not None): thread.start()
예제 #3
0
    def start(self, params = None, last_return = None):
        """
Start the server

:param params: Parameter specified
:param last_return: The return value from the last hook called.

:return: (mixed) Return value
:since:  v1.0.0
        """

        self._configure()
        Thread.start(self)

        Hook.call("dNG.pas.http.Server.onStartup", server = self)
        return self