close

How I call an async function without await?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How I call an async function without await in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How I call an async function without await?

  1. How I call an async function without await?

    Other way would be to use ensure_future function:
    import asyncio async def handler_message(request): ... loop = asyncio.get_event_loop() loop.ensure_future(perform_message(x,y,z)) ...

  2. call an async function without await

    Other way would be to use ensure_future function:
    import asyncio async def handler_message(request): ... loop = asyncio.get_event_loop() loop.ensure_future(perform_message(x,y,z)) ...

Method 1

One way would be to use create_task function:

import asyncio

async def handler_message(request):
    ...
    loop = asyncio.get_event_loop()
    loop.create_task(perform_message(x,y,z))
    ...

Method 2

Other way would be to use ensure_future function:

import asyncio

async def handler_message(request):
...
loop = asyncio.get_event_loop()
loop.ensure_future(perform_message(x,y,z))
...

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read