Replies: 1 comment
-
Yes :) Some helpful links:
PTB doesn't really create the loop, it just takes the one that's provided by Python
Ofc there are the usual problems with concurrency (race conditions, deadlocks can also occur) but that's independent of PTB. There is no general problem of running other asyncio code on the same event loop as ptb
🧸 |
Beta Was this translation helpful? Give feedback.
-
(Related to my question 4167, but may be also interesting for other users as a general question, so I'm splitting this as a new question)
All examples I found with PTB react only to events coming in via Telegram, i.e. updates from the server. The examples always seem to follow the pattern Request/Response:
In a way (viewed at a higher abstraction level), these examples are all very synchronous, ironically (for an asyncio heavy framework...)
There also is the JobQueue, which can be used to trigger callbacks at certain times, so this can be used to cause some action (alert message) or to poll for presence of external events (such as a change on a webpage).
However, I did not find any examples where PTB directly reacts to actual asynchronous events... such as: an incoming queue message, something happening on a file descriptor (example: stdin), an incoming TCP connection request on a listening socket or similar.
Did I miss these examples somehow? Is this even possible with the PTB architecture? My understanding is that this waiting for asynchronous events would need to be done as an asyncio call, and this would need to be hooked into the PTB asyncio event loop. But I did not find any examples for this on the PTB repo. Also I'm a bit unsure if this kind of "concurrency" (not strictly, because it is corountines...) is foreseen in PTB... i.e.: when PTB yields the event loop to another asyncio function, can that asyncio function call any PTB function it likes (like: send a message, change group config, ...), or is there a risk of running into some kind of deadlock/conflict?
As mentioned in the other thread: I'm not (yet?) an asyncio expert, so bear with me. Any suggestions and help are very much welcome.
Great to have this discussion forum available for questions!
Beta Was this translation helpful? Give feedback.
All reactions