我使用web.py实现了简单的web.py服务器。通过多线程模块,我可以在不同的端口上运行多个And服务器侦听实例。现在所有的实例都在永远监听http请求。我想走一条特别的路线。是否有一种方法可以阻止实例侦听(或完全终止特定线程)。
发布于 2014-06-05 17:28:56
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_()) https://stackoverflow.com/questions/7578629
复制相似问题