I have a simple Python app that runs in two threads. One is SMTP server, the other is HTTP server. When I start it in terminal it does not react on Ctrl+C. Here is the code:
import asyncore
import threading
import SimpleHTTPServer
import SocketServer
from smtpd import SMTPServer
class MailHoleSMTP(SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
pass
def run_smtp():
MailHoleSMTP(('localhost', 1025), None)
asyncore.loop()
def run_http():
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(('localhost', 1080), handler)
httpd.serve_forever()
if __name__ == '__main__':
http_thread = threading.Thread(target=run_http)
smtp_thread = threading.Thread(target=run_smtp)
http_thread.start()
smtp_thread.start()
http_thread.join()
smtp_thread.join()
I suspect that something might be wrong with that serve_forever() call, maybe it does not play well with threads or something. What can I do to make it react on Ctrl+C?
UPD: It does not work (for both threads) even if I run only one of the two threads.