RuntimeWarning: coroutine ‘function’ was never awaited

We Are Going To Discuss About RuntimeWarning: coroutine ‘function’ was never awaited. So lets Start this Python Article.

RuntimeWarning: coroutine ‘function’ was never awaited

  1. How to solve RuntimeWarning: coroutine 'function' was never awaited

    You should probably do await PersonalMessage().sendPersonalMessage(response, user_id_1) instead of using asyncio.run to execute this individual coroutine, unless you want to lose the benefits of using asyncio (ability to run other coroutines concurrently).
    asyncio.run should be the entry point of your whole program, and all your functions dealing with I/O should be declared as async def. The answers here and here elaborate a bit further.
     

  2. RuntimeWarning: coroutine 'function' was never awaited

    You should probably do await PersonalMessage().sendPersonalMessage(response, user_id_1) instead of using asyncio.run to execute this individual coroutine, unless you want to lose the benefits of using asyncio (ability to run other coroutines concurrently).
    asyncio.run should be the entry point of your whole program, and all your functions dealing with I/O should be declared as async def. The answers here and here elaborate a bit further.
     

Solution 1

You should probably do await PersonalMessage().sendPersonalMessage(response, user_id_1) instead of using asyncio.run to execute this individual coroutine, unless you want to lose the benefits of using asyncio (ability to run other coroutines concurrently).

asyncio.run should be the entry point of your whole program, and all your functions dealing with I/O should be declared as async def. The answers here and here elaborate a bit further.

Original Author Mikhail Gerasimov Of This Content

Solution 2

I got it I just had to import asyncio and wrap the function like this:

elif there_exists(['send', 'send']):
    speak("What should I send?")
    response = takeCommand()
    asyncio.run(PersonalMessage().sendPersonalMessage(response, user_id_1))
    speak("Message sent successfully")

Original Author Mikhail Gerasimov Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment