Closed truenicoco closed 9 months ago
Aiotdlib doesn't support running multiple clients at the moment.
Although tdlib supports it via its tdjson interface. You can slightly reimplement TDJson class for your use case.
Create multiple clients instead of one and handle "@client_id" field thoroughly instead of dropping those updates like it's implemented now in tdjson.py.
You can read more about this design here
I'll probably add multi-client support in the future, along with Pydantic v2.
Oh, I missed this line. Besides making sure we only call receive() from a single thread at once, and not dropping this client_id field, do you foresee any trouble supporting multiple clients? I'll give it a try, soonish.
I wouldn't name it a trouble.
But we need to make TDJson instance kind of singleton, handling all updates in it in separate single thread.
It might be good to rewrite Client class using pub/sub pattern instead of creating TDJson instance.
It's not a problem I think, but I have no time for now, therefore any pull requests are welcome 🙏
When trying to instantiate a second
aiotdlib.Client
while a first one is running, I run into this:I think this is due to
Client.receive
awaitingself.loop.run_in_executor(None, self.__tdjson.receive, timeout)
.I tried to fix that by wrapping
Client.receive
with a globalasyncio.Lock
:This prevents the crash, but it makes it impossible to authorize the second client:
This traceback is a bit dense because it's my full thing and not a MWE, but the interesting part is that
await self.api.get_authorization_state(request_id=AUTHORIZATION_REQUEST_ID)
times out, despiteReceived b'{"@type":"authorizationStateWaitTdlibParameters","@extra":{"request_id":"updateAuthorizationState"},"@client_id":2}'
. I did not manage to get anything more fruitful from my investigations.Any idea how to enable multi-account support?