2011-09-28 3 views
4

web.py를 사용하여 간단한 웹 서버를 구현했습니다. 그리고 멀티 스레딩 모듈을 통해 별도의 포트에서 수신 대기하는 웹 서버의 여러 인스턴스를 실행할 수 있습니다. 이제 모든 기관이 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_())