when I was testing multithreading, I found that a write module could not correctly respond to ctrl + c under multithreading. After my test, it should be caused by the paste module. How to deal with this situation?
import sys
import threading
import time
import bottle
HttpThread1 = None
HttpThread2 = None
@bottle.route("/hello")
def hello():
return "Hello World!"
def server1():
bottle.run(server="paste", port=8081)
def server2():
bottle.run(server="paste", port=8082)
def info():
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()
while True:
info()
time.sleep(1)
except KeyboardInterrupt:
sys.exit(1)
< hr >
my current solution is to use the multiprocessing library to solve the program exit problem.