You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am trying to set up a slack app using the Tornado adapter. I am trying to use AsyncApp instead of App, as that is the purpose of Tornado as an Asyncio server. however, it looks like the Tornado adapter tries to call self.app.dispatch and doesn't attempt to call await self.app.async_dispatch which is what the AsyncApp class uses. CC @seratch (Saw that you had worked on the Tornado code)
I am successfully able to get it working with App as seen below:
Since tornado.web.RequestHandler does not support async functions for get/post etc., the built-in Tornado adapter does not support AsyncApp use cases. See also: https://www.tornadoweb.org/en/stable/web.html
Checking the following resources may be helpful too. However, as far as I know, the async related decorator does not work with bolt-python in the way that you expect.
If you would like to make your listeners/middleware async for some reason, I'd suggest going with other modern asyncio-based frameworks such as AIOHTTP, FastAPI, Falcon, and Sanic. You can find examples here.
If you have a certain reason to use Tornado over others, I highly recommend going with App and synchronous code. With that being said, if you are keen to explore some ways to adjust the adapter, you can fork it and try whatever may better work for you. Here is the adapter code: https://github.com/slackapi/bolt-python/tree/v1.15.2/slack_bolt/adapter/tornado As you can see, there are only two files and they are quite simple.
Thank you for the response. tornado.web.RequestHandler does indeed support async def post, async def get, the stackoverflow is showing the Python2 way of handling Async. I am not sure why the Tornado team didn't document it well. Here is a benchmark comparison. Here is a way to test Tornado async.
mkdir -p /tmp/tornadotest
cd /tmp/tornadotest
python3 -m venv env
pip install tornado
vim server.py # Paste in the contents of server.py below and save
python server.py
# Visit http://localhost to confirm that you receive a text response: `GET request`
@castrapel Thanks for sharing this and I'm glad to hear that async functions are actually supported!
I am taking day offs until Friday. I will look into the enhancement after coming back. If you are in a hurry, please consider copying the adapter code and editing it to work with async functions for now.
Activity
seratch commentedon Nov 2, 2022
Hi @castrapel, thanks for asking the question.
Since
tornado.web.RequestHandlerdoes not support async functions for get/post etc., the built-in Tornado adapter does not support AsyncApp use cases. See also: https://www.tornadoweb.org/en/stable/web.htmlChecking the following resources may be helpful too. However, as far as I know, the async related decorator does not work with bolt-python in the way that you expect.
If you would like to make your listeners/middleware async for some reason, I'd suggest going with other modern asyncio-based frameworks such as AIOHTTP, FastAPI, Falcon, and Sanic. You can find examples here.
If you have a certain reason to use Tornado over others, I highly recommend going with App and synchronous code. With that being said, if you are keen to explore some ways to adjust the adapter, you can fork it and try whatever may better work for you. Here is the adapter code: https://github.com/slackapi/bolt-python/tree/v1.15.2/slack_bolt/adapter/tornado As you can see, there are only two files and they are quite simple.
I hope this was helpful to you.
castrapel commentedon Nov 2, 2022
Thank you for the response.
tornado.web.RequestHandlerdoes indeed supportasync def post,async def get, the stackoverflow is showing the Python2 way of handling Async. I am not sure why the Tornado team didn't document it well. Here is a benchmark comparison. Here is a way to test Tornado async.Contents of server.py:
seratch commentedon Nov 2, 2022
@castrapel Thanks for sharing this and I'm glad to hear that async functions are actually supported!
I am taking day offs until Friday. I will look into the enhancement after coming back. If you are in a hurry, please consider copying the adapter code and editing it to work with async functions for now.
castrapel commentedon Nov 3, 2022
Thanks @seratch, I'd appreciate your help here! Not in a big hurry on my end.
Fix #754 by adding the async version of Tornado adapter (#758)