Killing httpserver-thread on gui quit
Joonas Paalasmaa
joonas at olen.to
Tue Aug 21 09:49:27 EDT 2001
How can I set up a gui and a httpserver threads.
When gui's self.quit is executed,
httpserver should stop aswell.
Here's some non-working code.
#!/usr/bin/python
import threading, time, sys, BaseHTTPServer
from Tkinter import *
class HTTPWrapper(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type","text/html")
self.end_headers()
self.wfile.write("it works!")
PORT = 80
httpd = BaseHTTPServer.HTTPServer(("", PORT), HTTPWrapper)
class SimpleWidget(Frame):
def __init__(self):
Frame.__init__(self)
self.pack()
self.master.title("test")
Button(self,text="testing...", command=self.quit).pack(side=TOP)
def quit(self):
sys.exit(0)
thread1 = threading.Thread( target=httpd.serve_forever() )
thread2 = threading.Thread( target=SimpleWidget().mainloop() )
thread1.start()
thread2.start()
More information about the Python-list
mailing list