def get_server(addr, handler, debug=False):
		if debug:
			serv = ThreadingTCPServer(addr, handler, bind_and_activate=False)
			serv.allow_reuse_address = True
			serv.daemon_threads = True
			serv.server_bind()
			serv.server_activate()
		else:
			serv = ThreadingTCPServer(addr, handler)
		return serv
Ejemplo n.º 2
0
def main(address=None):
    try:
        LOGGER.info("Server up.")
        if address is None:
            ip = socket.gethostbyname(socket.gethostname())
            port = params.controller_port

            address = ip + ':' + str(port)

        LOGGER.info("Server listening address %s." % address)

        ip = address.split(':')[0]
        port = int(address.split(':')[1])

        server = ThreadingTCPServer((ip, port), request_handler)
        server.socket = secure_socket(sock=server.socket, server_side=True)
        server.daemon_threads = True

        LOGGER.info("Creating work thread...")
        serv_thread = threading.Thread(target=server.serve_forever)
        serv_thread.setDaemon(True)
        serv_thread.start()
        LOGGER.info("server is running at %s." % address)

        a_table = access_table()
        while True:
            time.sleep(5)
            # LOGGER.critical(a_table.print())
    except KeyboardInterrupt:
        LOGGER.info("Receive keyboard interrupt, shut down...")
    except BaseException:
        LOGGER.error("Catch unhandled exception.")
        traceback.print_exc()
    finally:
        try:
            LOGGER.info("Exit handle loop...")
            server.shutdown()
            LOGGER.info("Close socket...")
            server.server_close()
        except:
            pass
        try:
            LOGGER.info("Wait all request handler threads...")
            serv_thread.join()
        except:
            pass
        LOGGER.info("Server down.")
Ejemplo n.º 3
0
def root(strating, m_dict, m_lock, rev_Queue, send_Queue):

    if strating == True:

        global lock
        global Queue_send_to_poster
        lock = m_lock
        Queue_send_to_poster = send_Queue  # 傳給FLASKtest的訊息Queue
        lock.acquire()
        global user_list
        user_list = m_dict
        serv = ThreadingTCPServer(('0.0.0.0', 20000), EchoHandler)
        serv.daemon_threads = True
        print("RUN (ctrl + C to Exit)")
        lock.release()

        t = threading.Thread(target=waiting_QueueEvent, args=(rev_Queue, ))
        t.start()
        serv.serve_forever()
Ejemplo n.º 4
0
def serve():
    s = ThreadingTCPServer(('0.0.0.0', PORT), Handler)
    s.daemon_threads = True
    s.serve_forever()