我已经使用 web.py 实现了简单的网络服务器。通过多线程模块,我可以在不同的端口上运行多个网络服务器实例。现在所有的实例都在永远监听 http 请求。我想踩一个特定的线程。有没有办法阻止实例监听(或完全杀死特定线程。)
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()
Run Code Online (Sandbox Code Playgroud)
框架.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_())
Run Code Online (Sandbox Code Playgroud)