开发者

How to stop webserver (implemented through web.py and threading)

开发者 https://www.devze.com 2023-04-09 02:56 出处:网络
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.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号