Not using asyncio.run() raises this error: RuntimeError: no running event loop, so I added an example to work properly with AsyncioScheduler

AEIMS 2025-05-04 14:50:19 +03:30
parent 488ece26bd
commit 308b49c9bb

@ -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.