Exemplo n.º 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
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 4
0
    def __init__(self):
        """
Constructor __init__(Handler)

:since: v0.2.00
        """

        Thread.__init__(self)

        self.active_id = -1
        """
Queue ID
        """
        self.address = None
        """
Address of the received data
        """
        self.address_family = None
        """
Address family of the received data
        """
        self.data = Binary.BYTES_TYPE()
        """
Data buffer
        """
        self.log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False)
        """
The LogHandler is called whenever debug messages should be logged or errors
happened.
        """
        self.server = None
        """
Server instance
        """
        self.socket = None
        """
Socket instance
        """
        self.timeout = int(Settings.get("pas_global_server_socket_data_timeout", 0))
        """
Request timeout value
        """

        if (self.timeout < 1): self.timeout = int(Settings.get("pas_global_socket_data_timeout", 30))
Exemplo n.º 5
0
    def __init__(self):
        """
Constructor __init__(GlibThread)

:since: v0.2.00
        """

        Thread.__init__(self)

        self.log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False)
        """
The LogHandler is called whenever debug messages should be logged or errors
happened.
        """
        self.mainloop = None
        """
Active mainloop instance
        """

        Hook.register_weakref("dNG.pas.Status.onShutdown", self.stop)
Exemplo n.º 6
0
    def __init__(self):
        """
Constructor __init__(AbstractServer)

:since: v1.0.0
        """

        Thread.__init__(self)

        self.host = None
        """
Configured server host
        """
        self._log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False)
        """
The LogHandler is called whenever debug messages should be logged or errors
happened.
        """
        self.port = None
        """
Configured server port
        """
        self.socket_hostname = None
        """
Socket server hostname
        """

        socket_hostname = getfqdn()

        try:
            getaddrinfo(socket_hostname, None)
            self.socket_hostname = socket_hostname
        except socket_error: self.socket_hostname = gethostname()

        self.socket_hostname = self.socket_hostname.lower()

        Hook.register_weakref("dNG.pas.http.Server.getHost", self.get_host)
        Hook.register_weakref("dNG.pas.http.Server.getPort", self.get_port)