我在测试多线程时,发现有写模块无法在多线程下正确响应ctrl+c,经过我测试,应该为paste模块所致,请问这种情况如何处理较好?importsysimportthreadingimporttimeimportbottleHttpThread1=NoneHttpThread2=None@bottle.route('/hello')defhello():return"HelloWorld!"defserver1():bottle.run(server='paste',port=8081)defserver2():bottle.run(server='paste',port=8082)definfo():print(threading.active_count())try:HttpThread1=threading.Thread(target=server1,args=())HttpThread1.setDaemon(True)HttpThread1.start()HttpThread2=threading.Thread(target=server2,args=())HttpThread2.setDaemon(True)HttpThread2.start()whileTrue:info()time.sleep(1)exceptKeyboardInterrupt:sys.exit(1)我现有的解决方案为采用multiprocessing库来解决程序退出问题。
慕娘9325324
HUX布斯
相关分类