1

离开这个例子,有人可以告诉我为什么我不能用 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()
4

1 回答 1

2

像这样启动线程:

#!/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)
于 2013-10-17T00:34:44.197 回答