从这个example开始,有人可以告诉我为什么我无法使用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()

最佳答案

像这样启动线程:

#!/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)

关于python - 无法退出异步Web.py Web服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19259451/

10-10 06:10