1

Going off of this example, could someone please tell me why I can not kill this program with Ctrl+C:

#!/usr/bin/env python
import web
import threading
class MyWebserver(threading.Thread):
   def run (self):
      urls = ('/', 'MyWebserver')
      app = web.application(urls, globals())
      app.run()

   def POST (self):
      pass

if __name__ == '__main__':
   MyWebserver().start()
Community
  • 1
  • 1
puk
  • 16,318
  • 29
  • 119
  • 199
  • BTW, I did try to use Python's Tornado Web Server, but it has little to no documentation. – puk Oct 08 '13 at 22:14

1 Answers1

2

Launch the thread like this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import web
import threading

from time import sleep

class MyWebserver(threading.Thread):
    def run(self):
        urls = ('/', 'MyWebserver')
        app = web.application(urls, globals())
        app.run()

if __name__ == '__main__':
    t = MyWebserver()
    t.daemon = True
    t.start()
    while True:
        sleep(100)
cdonts
  • 9,304
  • 4
  • 46
  • 72
  • 1
    Yes, that works. Thank you. Could you please convert it into a minimal working example in case someone wants to borrow it. – puk Oct 17 '13 at 00:44
  • What do you mean? Apply that code into a working example of a simple web.py application? – cdonts Oct 17 '13 at 02:04
  • Sorry, Minimal working example is a snippet of code whereby if you copy pasted it into a file `foo.py`, it would run successfully – puk Oct 17 '13 at 05:48
  • For example, you are missing `#!/usr/bin/env python`, the import statements `import web` and `from time import sleep`. – puk Oct 17 '13 at 05:49