B
B
buymyopps2021-01-16 15:02:49
Python
buymyopps, 2021-01-16 15:02:49

Telegram bot latency problem?

Hello, I used the aiogram lib for writing. The problem is that the bot calls a function that makes a request to a web resource. So while this request is being executed, the bot cannot be used, it does not respond, does not process the user's actions in any way. How can this be fixed? Make functions asynchronous or what? Help to understand, please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alekssamos, 2021-01-16
@buymyopps

Wait, is that what they call it?
Do import asyncioit at the beginning Put your long query here:

async def longrequest():
  # ............

And where you need to call it write:
asyncio.create_task(longrequest())
And that's it.
If it doesn't help, study the aiohttp library and make a request through it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question