2011-09-28 43 views
4

我已經使用web.py實現了簡單的網絡服務器。 通過多線程模塊,我可以運行監聽不同端口的多個Web服務器實例。 現在所有的instances都在監聽http請求。我想要介紹一個特定的線程。 有沒有辦法從聽停止實例(或完全殺死特定的線程。)如何停止網絡服務器(通過web.py和線程實現)

回答

0

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_())