diff --git a/pyrogram/methods/messages/inline_session.py b/pyrogram/methods/messages/inline_session.py index bfc323a2..354cb70f 100644 --- a/pyrogram/methods/messages/inline_session.py +++ b/pyrogram/methods/messages/inline_session.py @@ -16,29 +16,22 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from asyncio import Lock - import pyrogram from pyrogram import raw from pyrogram.errors import AuthBytesInvalid from pyrogram.session import Session from pyrogram.session.auth import Auth -lock = Lock() -sessions = {} - async def get_session(client: "pyrogram.Client", dc_id: int): if dc_id == await client.storage.dc_id(): return client - async with lock: - global sessions + async with client.media_sessions_lock: + if client.media_sessions.get(dc_id): + return client.media_sessions[dc_id] - if sessions.get(dc_id): - return sessions[dc_id] - - session = sessions[dc_id] = Session( + session = client.media_sessions[dc_id] = Session( client, dc_id, await Auth(client, dc_id, False).create(), False, is_media=True