Is this code asynchronous?

async def send_message(update):
 api.messages.send(user_id= ......) # Makes the request 
url = ...
while 1:
 updates = requests.get(url).json() #Add
 for update in updates:
 if r['type'] == 'new_message':
 task = event_loop.create_task(send_message(update))
 event_loop.run_until_complete(task)

I realized that if you often send messages, the mistake that many requests per second. To add a delay?
March 23rd 20 at 19:43
1 answer
March 23rd 20 at 19:45
No, it is not. Absolutely all its parts are synchronous, attempt to use the coroutine is meaningless.
why? How to make it asynchronous? - Chaz commented on March 23rd 20 at 19:48
@Chaz, get rid of blocking calls. - Fae.Rempel commented on March 23rd 20 at 19:51
@Fae.Rempel, than there are blocking calls? - Chaz commented on March 23rd 20 at 19:54
@Chaz,
  1. requests.get()
  2. event_loop.run_until_complete()
  3. api.messages.send()
- Fae.Rempel commented on March 23rd 20 at 19:57
@Fae.Rempel, I think it is better to use threads for such a task - Chaz commented on March 23rd 20 at 20:00

Find more questions by tags Asynchronous programmingPython