How to move SimpleSocket server into a background process

前端 未结 2 1867
离开以前
离开以前 2020-12-12 04:04

I have a simple socketServer that works perfectly on the main thread.

#Server PORT
PORT = 8020
#reassign variables
Handler = Server #this is a S         


        
2条回答
  •  离开以前
    2020-12-12 04:31

    You might need threading/_thread

    def server():
        ....
    
    import _thread
    _thread.start_new_thread(server, ())
    

    This basically starts the server function on a different thread.

    EDIT: In this case in your def server(): you a global variable threadIsRunning, if this is valued to True it should continue, but if it is valued to False run thread.exit() this should all be in some sort of loop.

提交回复
热议问题