Home  >  Q&A  >  body text

thread - python 线程,消息处理系统。怎样在维持主线程的同时结束掉子线程?

写了一个类似于消息处理系统
主线程是监听端口,有消息过来就打开一个新的子线程,如果子线程遇到错误怎么退出呢?杀死掉这个子线程但是维持主线程依旧监听端口?
我用的是threading 谢谢!

threading.Thread(target=login.login, args=(vrc_waite,username,password,phone,), name=username).start()


天蓬老师天蓬老师2740 days ago725

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 10:21:26

    The child thread should exit by itself. If you are using a socket, the main thread must create the socket listener. After receiving the message, it creates the socket client and then passes it to the child thread. The child thread operates on the client. If an error occurs, it will not affect the listener

    reply
    0
  • Cancelreply