I have determined that this issue is because I was using the Git Bash console on Windows. When I use the regular command prompt, everything works as expected. I suspect Git Bash is catching ^C and killing the process.
Python: Tornado ioloop killed with no exceptions on KeyboardInterrupt
-
12-10-2022 - |
سؤال
When I press ^C
when blocking on tornado's ioloop.start()
in the following program, Python quits immediately and no KeyboardInterrupt (or any other exception) is raised. What is going on and how can I catch ^C
?
import tornado.ioloop
import tornado.web
ioloop = tornado.ioloop.IOLoop.instance()
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
# has no effect
# tornado.ioloop.PeriodicCallback(lambda:None, 1000).start()
print 'starting'
try:
ioloop.start()
except KeyboardInterrupt:
print '^C pressed'
finally:
print 'done'
Output:
$ /c/Python27x32/python test.py
starting
$
Expected output:
$ /c/Python27x32/python test.py
starting
^C pressed
done
$
I'm running:
- Windows 8.0 x64,
- Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
- tornado==3.2
المحلول
نصائح أخرى
Windows has different signal for console
try Ctrl + break or Ctrl + D
لا تنتمي إلى StackOverflow