mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-15 10:32:28 +03:00
added this part to solve ConnectionError: Cannot send requests while disconnected
parent
308b49c9bb
commit
3c3a77755f
|
@ -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).
|
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:
|
You can also use `while` loops:
|
||||||
|
|
||||||
|
@ -54,6 +54,15 @@ or:
|
||||||
loop.run_forever()
|
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.
|
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.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user