From 3c3a77755f67394991dbd8d5d4657da2b241db1e Mon Sep 17 00:00:00 2001 From: AEIMS <66196824+aeims@users.noreply.github.com> Date: Sun, 4 May 2025 15:32:06 +0330 Subject: [PATCH] added this part to solve `ConnectionError: Cannot send requests while disconnected` --- Scheduling-Functions.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Scheduling-Functions.md b/Scheduling-Functions.md index c711886..022dd5d 100644 --- a/Scheduling-Functions.md +++ b/Scheduling-Functions.md @@ -29,7 +29,7 @@ foo_cb() This schedules itself again when it runs, so it is always running. It runs, 10 minutes pass, it schedules itself again, and repeat. This is similar to JavaScript's [`setTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout). -> **Important note**. Do **not** call the synchronous function when you schedule it, or it will recurse forever. `loop.call_later(delay, func())` won't work, but `loop.call_later(delay, func)` will. +**Important note**. Do **not** call the synchronous function when you schedule it, or it will recurse forever. `loop.call_later(delay, func())` won't work, but `loop.call_later(delay, func)` will. You can also use `while` loops: @@ -54,6 +54,15 @@ or: loop.run_forever() ``` +Also if you encounter this error `ConnectionError: Cannot send requests while disconnected` that means you first need to start the client `client.start()` then call `foo_cb()`: + +```python +client.start() + +foo_cb() + +client.run_until_disconnected() +``` --- If you don't mind using other libraries, [`aiocron`](https://github.com/gawel/aiocron) is a good option. See https://crontab.guru/ to learn its time syntax.