发生异常:NotImplementedError

Exception has occurred: NotImplementedError

第一次执行此操作并在 app.listen(端口)

处出现异常
import tornado.web
import tornado.ioloop

class basicRequestHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, World this is a python command executed from the  backend.")

if __name__ == "__main__":
    app = tornado.web.Application([
        (r"/", basicRequestHandler)
    ])

    port = 8882
    app.listen(port)#Getting exception here 
    print(f"Application is ready and listening on port {port}")
    tornado.ioloop.IOLoop.current().start()

在 python 3.8:

import tornado.ioloop
import tornado.web
import asyncio

class basicRequestHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, World this is a python command executed from the  backend.")

if __name__ == "__main__":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    app = tornado.web.Application([
    (r"/", basicRequestHandler)
    ])
    port = 8882
    app.listen(port)
    print(f"Application is ready and listening on port {port}")
    tornado.ioloop.IOLoop.current().start()

@gdi313 的回答是正确的,但让我解释一下为什么我们必须在我们的代码中包含 asyncio,

till python3.7 Tornado 默认选择 'WindowsSelectorEventLoop',而 python 3.8 默认不兼容 windows

这就是为什么如果您的应用程序在 windows 上运行,使用 tornado 必须有线 "asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())"开头

希望这对遇到错误的人有用!

https://github.com/tornadoweb/tornado/pull/2686/files