Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

web.py

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.)

like image 651
babbu Pehlwan Avatar asked Nov 14 '22 16:11

babbu Pehlwan


1 Answers

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_()) 
like image 147
Ricky Wilson Avatar answered Jan 18 '23 15:01

Ricky Wilson