I am running a webpy server from a worker thread in a pygtk program I
wrote.  I was looking for a way to start/stop the server from the main
thread.  I saw a previous thread on this group that said using raise
KeyboardInterrupt, but without access to webpy's 'main loop', it's
difficult to get it to execute in webpy's thread.

The only way I could figure it out so far is demonstrated below.  I
was just wondering if there was a cleaner way.



import web
from threading import Thread

class Serva(Thread):
    urls = (
    '/exit','exit',
    "/.*", "hello",
    )

    def run(self):
        app = web.application(self.urls, Serva.__dict__)
        app.run()

    class hello:
        def GET(self):
            return 'Hello, world!'

    class exit:
        def GET(self):
            raise KeyboardInterrupt

    def stop_(self):
        raise KeyboardInterrupt

if __name__ == "__main__":
    import time, httplib
    a = Serva()
    a.start()
    print 'started serva'
    time.sleep(2)
    httplib.HTTPConnection('localhost:8088').request('GET','/exit')
    a.join()
    print 'stopping'

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to