Skip to content

Commit e68da74

Browse files
Further improve the session-switching mechanism for inline bots (pyrogram#739)
* Ability to run multiple bot. Global session creates a problem for other bot. As that session was generated for another bot can't be used by this bot. * Use the existing media session lock Co-authored-by: Dan <[email protected]>
1 parent aea1ffc commit e68da74

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

pyrogram/methods/messages/inline_session.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,22 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from asyncio import Lock
20-
2119
import pyrogram
2220
from pyrogram import raw
2321
from pyrogram.errors import AuthBytesInvalid
2422
from pyrogram.session import Session
2523
from pyrogram.session.auth import Auth
2624

27-
lock = Lock()
28-
sessions = {}
29-
3025

3126
async def get_session(client: "pyrogram.Client", dc_id: int):
3227
if dc_id == await client.storage.dc_id():
3328
return client
3429

35-
async with lock:
36-
global sessions
37-
38-
if sessions.get(dc_id):
39-
return sessions[dc_id]
30+
async with client.media_sessions_lock:
31+
if client.media_sessions.get(dc_id):
32+
return client.media_sessions[dc_id]
4033

41-
session = sessions[dc_id] = Session(
34+
session = client.media_sessions[dc_id] = Session(
4235
client, dc_id,
4336
await Auth(client, dc_id, False).create(),
4437
False, is_media=True

0 commit comments

Comments
 (0)