當前位置: 首頁>>代碼示例>>Python>>正文


Python socketserver.ThreadingTCPServer方法代碼示例

本文整理匯總了Python中six.moves.socketserver.ThreadingTCPServer方法的典型用法代碼示例。如果您正苦於以下問題:Python socketserver.ThreadingTCPServer方法的具體用法?Python socketserver.ThreadingTCPServer怎麽用?Python socketserver.ThreadingTCPServer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在six.moves.socketserver的用法示例。


在下文中一共展示了socketserver.ThreadingTCPServer方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _start_thread

# 需要導入模塊: from six.moves import socketserver [as 別名]
# 或者: from six.moves.socketserver import ThreadingTCPServer [as 別名]
def _start_thread(self, system):
        self._server = socketserver.ThreadingTCPServer(
            ("", 0),        # Let the OS pick a port for us
            FMSTCPHandler,  # Handler of the requests
            False)
        self._server.allow_reuse_address = True
        self._server.server_bind()
        self._server.server_activate()
        self._server.terminate = False
        self._server.system = system
        self._server.sleep_in_seconds = self._config["sleep"]
        if "min_event_per_burst" in self._config:
            self._server.min_event_per_burst = \
                int(self._config["min_event_per_burst"])
        else:
            self._server.min_event_per_burst = 500

        self._server_thread = threading.Thread(target=self._serve_forever)
        self._server_thread.start()
        port_used = self._server.socket.getsockname()[1]
        return port_used 
開發者ID:openstack,項目名稱:monasca-analytics,代碼行數:23,代碼來源:base.py

示例2: _configure_server

# 需要導入模塊: from six.moves import socketserver [as 別名]
# 或者: from six.moves.socketserver import ThreadingTCPServer [as 別名]
def _configure_server(self):
        """Creates and configures the Server object

        The server object is configured according to
        the configuration of this source module
        """
        self._server = socketserver.ThreadingTCPServer(
            (self._config["params"]["host"],
             self._config["params"]["port"]),
            MonanasTCPHandler, False)
        self._server.generate = getattr(
            self, "_generate_" +
            self._config["params"]["model"]["name"])
        # self._server.validate = getattr(
        #    source_model, self._config["validate"])
        self._server.allow_reuse_address = True
        self._server.server_bind()
        self._server.server_activate()
        self._server.terminate = False
        self._server.generate_alerts_per_second =\
            self._config["params"]["alerts_per_burst"]
        self._server.generate_idle_time_between_bursts =\
            self._config["params"]["idle_time_between_bursts"]
        self._server_thread = th.Thread(target=self._server.serve_forever)
        self._is_server_running = False 
開發者ID:openstack,項目名稱:monasca-analytics,代碼行數:27,代碼來源:randoms.py

示例3: create_dstream

# 需要導入模塊: from six.moves import socketserver [as 別名]
# 或者: from six.moves.socketserver import ThreadingTCPServer [as 別名]
def create_dstream(self, ssc):
        """Initiates the system in a TCP server, and creates the dstream object

        The _dstream object is created before this source is bound
        to the consumers. It uses a socketTextStream, to read data from
        the ThreadingTCPServer.

        :type ssc: pyspark.streaming.StreamingContext
        :param ssc: Spark Streaming Context that provides the data input
        """
        system = LeafNodes(self._create_system())
        port = self._start_thread(system)
        return ssc.socketTextStream(
            "localhost",
            port) 
開發者ID:openstack,項目名稱:monasca-analytics,代碼行數:17,代碼來源:base.py

示例4: create_dstream

# 需要導入模塊: from six.moves import socketserver [as 別名]
# 或者: from six.moves.socketserver import ThreadingTCPServer [as 別名]
def create_dstream(self, ssc):
        """Dstream object creation

        The _dstream object is created before this source is bound
        to the consumers. It uses a socketTextStream, to read data from
        the ThreadingTCPServer.

        :type ssc: pyspark.streaming.StreamingContext
        :param ssc: Spark Streaming Context
        """
        self._start_server()
        self._dstream = ssc.socketTextStream(
            self._config["params"]["host"],
            self._config["params"]["port"]) 
開發者ID:openstack,項目名稱:monasca-analytics,代碼行數:16,代碼來源:randoms.py

示例5: __init__

# 需要導入模塊: from six.moves import socketserver [as 別名]
# 或者: from six.moves.socketserver import ThreadingTCPServer [as 別名]
def __init__(self, host='', port=16838, *args, **kwargs):
        socketserver.ThreadingTCPServer.__init__(self, (host, port), ThreadedTCPRequestHandler)
        self.requests = {}
        self.server_thread = threading.Thread(target=self.serve_forever)
        self.server_thread.setDaemon(True)
        self.server_thread.start()
        self.onConnected = None
        self.onDisconnected = None
        self.onData = None 
開發者ID:devcartel,項目名稱:pymt5,代碼行數:11,代碼來源:pymt5.py

示例6: __init__

# 需要導入模塊: from six.moves import socketserver [as 別名]
# 或者: from six.moves.socketserver import ThreadingTCPServer [as 別名]
def __init__(self, *args, **kwargs):
        super(SockListener, self).__init__(*args, **kwargs)
        # inject service_handler
        SockBoltHandler.service_handler = self.handler
        self.server = ThreadingTCPServer(self.address, SockBoltHandler) 
開發者ID:sofastack,項目名稱:sofa-bolt-python,代碼行數:7,代碼來源:sock_listener.py

示例7: start_server

# 需要導入模塊: from six.moves import socketserver [as 別名]
# 或者: from six.moves.socketserver import ThreadingTCPServer [as 別名]
def start_server(sync):
        # type: (bool) -> int
        """Start the TCP server."""
        # N.B. port = 0 chooses any arbitrary open one
        CoqtailHandler.sync = sync
        CoqtailServer.serv = ThreadingTCPServer(("localhost", 0), CoqtailHandler)
        CoqtailServer.serv.daemon_threads = True
        _, port = CoqtailServer.serv.server_address

        serv_thread = threading.Thread(target=CoqtailServer.serv.serve_forever)
        serv_thread.daemon = True
        serv_thread.start()

        return port 
開發者ID:whonore,項目名稱:Coqtail,代碼行數:16,代碼來源:coqtail.py


注:本文中的six.moves.socketserver.ThreadingTCPServer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。