close

[Solved] RuntimeError: There is no current event loop in thread in async + apscheduler

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error RuntimeError: There is no current event loop in thread in async + apscheduler in python. So Here I am Explain to you all the possible solutions here.

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

How RuntimeError: There is no current event loop in thread in async + apscheduler Error Occurs?

Today I get the following error RuntimeError: There is no current event loop in thread in async + apscheduler in python.

How To Solve RuntimeError: There is no current event loop in thread in async + apscheduler Error ?

  1. How To Solve RuntimeError: There is no current event loop in thread in async + apscheduler Error ?

    To Solve RuntimeError: There is no current event loop in thread in async + apscheduler Error Just pass fetch_all to scheduler.add_job() directly. The asyncio scheduler supports coroutine functions as job targets.

  2. RuntimeError: There is no current event loop in thread in async + apscheduler

    To Solve RuntimeError: There is no current event loop in thread in async + apscheduler Error Just pass fetch_all to scheduler.add_job() directly. The asyncio scheduler supports coroutine functions as job targets.

Solution 1

Just pass fetch_all to scheduler.add_job() directly. The asyncio scheduler supports coroutine functions as job targets.

If the target callable is not a coroutine function, it will be run in a worker thread (due to historical reasons), hence the exception.

Solution 2


In your def demo_async(urls), try to replace:

loop = asyncio.get_event_loop()

with:

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

Summery

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

Also, Read