|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import List |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from .idle import idle |
| 23 | + |
| 24 | + |
| 25 | +async def compose(clients: List["pyrogram.Client"]): |
| 26 | + """Run multiple clients at once. |
| 27 | +
|
| 28 | + This method can be used to run multiple clients at once and can be found directly in the ``pyrogram`` package. |
| 29 | +
|
| 30 | + If you want to run a single client, you can use Client's bound method :meth:`~pyrogram.Client.run`. |
| 31 | +
|
| 32 | + Parameters: |
| 33 | + clients (List of :obj:`~pyrogram.Client`): |
| 34 | + A list of client objects to run. |
| 35 | +
|
| 36 | + Example: |
| 37 | + .. code-block:: python |
| 38 | +
|
| 39 | + import asyncio |
| 40 | + from pyrogram import Client, compose |
| 41 | +
|
| 42 | +
|
| 43 | + async def main(): |
| 44 | + app1 = Client("account1") |
| 45 | + app2 = Client("account2") |
| 46 | + app3 = Client("account3") |
| 47 | +
|
| 48 | + ... |
| 49 | +
|
| 50 | + await compose([app1, app2, app3]) |
| 51 | +
|
| 52 | +
|
| 53 | + asyncio.run(main()) |
| 54 | +
|
| 55 | + """ |
| 56 | + for c in clients: |
| 57 | + await c.start() |
| 58 | + |
| 59 | + await idle() |
| 60 | + |
| 61 | + for c in clients: |
| 62 | + await c.stop() |
0 commit comments