'_asyncio.Future' object has no attribute 'create_future'

Viewed 25

I am working on building an asyncio.Future integration with my Tornado app so I can request a callback. Essentially, I instantiated a class within a class, this creates a future and adds a callback to the function.

However, when I call this I get a bunch of error messages:

Traceback (most recent call last):
  File "/Users/robot/tornado/venv/lib/python3.8/site-packages/tornado/web.py", line 1713, in _execute
    result = await result
  File "pending/request_seven.py", line 31, in get
    await self.scheduleFuture._future(client.fetch('https://books.toscrape.com'), self.on_response)
  File "pending/request_seven.py", line 25, in _future
    fut = self.create_future()
AttributeError: '_asyncio.Future' object has no attribute 'create_future'

Here is what I have tried with my script:

define('port', default = 9057, help="run port 9060", type=int)

class requestFour(tornado.web.RequestHandler):

    class scheduleFuture(asyncio.SelectorEventLoop):

        @staticmethod
        def unwrapper(fut: asyncio.Future, function):
            return function()

        def _future(self, fun1 ):
            fut = self.create_future()
            fut.add_done_callback(func(self.unwrapper, function=fun1))
            return fut

    async def get(self):
        client = tornado.httpclient.AsyncHTTPClient()
        await self.scheduleFuture._future(client.fetch('https://books.toscrape.com'), self.on_response)


    def on_response(self, response):
        body = response.body
        self.write(body) 
        self.finish()

def my_app():
    app = tornado.web.Application(handlers = [(r'/', requestFour)])
    http_server = tornado.httpserver.HTTPServer(app)
    return http_server

async def main():
    app = my_app()
    app.listen(options.port)
    shutdown_event = asyncio.Event()
    await shutdown_event.wait()

if __name__ == '__main__':
    asyncio.run(main())
0 Answers
Related