How to stop webserver (implemented through web.py and threading)
I have implemented simple webserver using web.py. And through multithreading module, I am able to run multiple instances of webserver listening on separate ports. Now all the instnces are listening http requests forever. and I want to 开发者_开发技巧step a particular thread. Is there a way to stop an instance from listening (or kill particular thread altogether.)
api.py
import web
import threading
urls = (
'/', 'index',
)
class index:
def GET(self):
return "I'm lumberjack and i'm ok"
def run():
app = web.application(urls, globals())
t = threading.Thread(target=app.run)
t.setDaemon(True) # So the server dies with the main thread
t.setName('api-thread')
t.start()
frame.py
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
import api
app = QApplication(sys.argv)
web = QWebView()
api.run()
web.load(QUrl("http://0.0.0.0:8080/"))
web.show()
sys.exit(app.exec_())
精彩评论