From 308b49c9bb7f1b8394e8194168c6d5c07fefc669 Mon Sep 17 00:00:00 2001 From: AEIMS <66196824+aeims@users.noreply.github.com> Date: Sun, 4 May 2025 14:50:19 +0330 Subject: [PATCH] Not using asyncio.run() raises this error: RuntimeError: no running event loop, so I added an example to work properly with AsyncioScheduler --- Scheduling-Functions.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Scheduling-Functions.md b/Scheduling-Functions.md index 67b5ca5..c711886 100644 --- a/Scheduling-Functions.md +++ b/Scheduling-Functions.md @@ -88,6 +88,21 @@ scheduler = AsyncIOScheduler() scheduler.add_job(this_will_run_at_every_one_hour, 'interval', minutes=60) scheduler.start() ``` +Note that for actually being able to use this scheduler you will need to import `asyncio.run` and write an async main loop function to run your script and avoid errors. example is given below(edit according to your own code if needed): + +```python +async def main(): + await client.start() + scheduler.start() + print("Scheduler started...\n(Press Ctrl+C to stop this)") + await client.run_until_disconnected() + +if __name__ == "__main__": + try: + asyncio.run(main()) + except (KeyboardInterrupt, SystemExit): + pass +``` You can also set a custom time zone and can also use a database for running these functions. This is more advanced and works smoothly with Telethon.