{"id":956,"hash":"5bbaea4037f2d6fdb57c2362ce87ee348217388f1bb5224eba8b92c5c797f5b7","pattern":"RuntimeError: There is no current event loop in thread in async + apscheduler","full_message":"I have a async function and need to run in with apscheduller every N minutes.\nThere is a python code below\n\nURL_LIST = ['<url1>',\n            '<url2>',\n            '<url2>',\n            ]\n\ndef demo_async(urls):\n    \"\"\"Fetch list of web pages asynchronously.\"\"\"\n    loop = asyncio.get_event_loop() # event loop\n    future = asyncio.ensure_future(fetch_all(urls)) # tasks to do\n    loop.run_until_complete(future) # loop until done\n\nasync def fetch_all(urls):\n    tasks = [] # dictionary of start times for each url\n    async with ClientSession() as session:\n        for url in urls:\n            task = asyncio.ensure_future(fetch(url, session))\n            tasks.append(task) # create list of tasks\n        _ = await asyncio.gather(*tasks) # gather task responses\n\nasync def fetch(url, session):\n    \"\"\"Fetch a url, using specified ClientSession.\"\"\"\n    async with session.get(url) as response:\n        resp = await response.read()\n        print(resp)\n\nif __name__ == '__main__':\n    scheduler = AsyncIOScheduler()\n    scheduler.add_job(demo_async, args=[URL_LIST], trigger='interval', seconds=15)\n    scheduler.start()\n    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))\n\n    # Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.\n    try:\n        asyncio.get_event_loop().run_forever()\n    except (KeyboardInterrupt, SystemExit):\n        pass\n\nBut when i tried to run it i have the next error info\n\nJob \"demo_async (trigger: interval[0:00:15], next run at: 2017-10-12 18:21:12 +04)\" raised an exception.....\n..........\\lib\\asyncio\\events.py\", line 584, in get_event_loop\n    % threading.current_thread().name)\nRuntimeError: There is no current event loop in thread '<concurrent.futures.thread.ThreadPoolExecutor object at 0x0356B150>_0'.\n\nCould you please help me with this? \nPython 3.6, APScheduler 3.3.1,","ecosystem":"pypi","package_name":"python-3.x","package_version":null,"solution":"Just pass fetch_all to scheduler.add_job() directly. The asyncio scheduler supports coroutine functions as job targets.\n\nIf the target callable is not a coroutine function, it will be run in a worker thread (due to historical reasons), hence the exception.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler","votes":125,"created_at":"2026-04-19T04:52:05.808140+00:00","updated_at":"2026-04-19T04:52:07.347943+00:00"}