Skip to content

Commit d43a89c

Browse files
committed
Updated to 1.4.6 from the latest commit on the official repo https://github.com/pyrogram/pyrogram
1 parent 9ec83a4 commit d43a89c

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

pyrogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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-
__version__ = "1.4.1"
19+
__version__ = "1.4.6"
2020
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
2121
__copyright__ = "Copyright (C) 2017-present Dan <https://github.com/delivrance>"
2222

pyrogram/connection/connection.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ def close(self):
7777
log.info("Disconnected")
7878

7979
async def send(self, data: bytes):
80-
try:
81-
await self.protocol.send(data)
82-
except Exception:
83-
raise OSError
80+
await self.protocol.send(data)
8481

8582
async def recv(self) -> Optional[bytes]:
8683
return await self.protocol.recv()

pyrogram/sync.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,23 @@ def async_to_sync(obj, name):
3030
function = getattr(obj, name)
3131
main_loop = asyncio.get_event_loop()
3232

33-
async def consume_generator(coroutine):
34-
return types.List([i async for i in coroutine])
33+
def async_to_sync_gen(agen, loop, is_main_thread):
34+
async def anext(agen):
35+
try:
36+
return await agen.__anext__(), False
37+
except StopAsyncIteration:
38+
return None, True
39+
40+
while True:
41+
if is_main_thread:
42+
item, done = loop.run_until_complete(anext(agen))
43+
else:
44+
item, done = asyncio.run_coroutine_threadsafe(anext(agen), loop).result()
45+
46+
if done:
47+
break
48+
49+
yield item
3550

3651
@functools.wraps(function)
3752
def async_to_sync_wrap(*args, **kwargs):
@@ -51,7 +66,7 @@ def async_to_sync_wrap(*args, **kwargs):
5166
return loop.run_until_complete(coroutine)
5267

5368
if inspect.isasyncgen(coroutine):
54-
return loop.run_until_complete(consume_generator(coroutine))
69+
return async_to_sync_gen(coroutine, loop, True)
5570
else:
5671
if inspect.iscoroutine(coroutine):
5772
if loop.is_running():
@@ -66,7 +81,7 @@ async def coro_wrapper():
6681
if loop.is_running():
6782
return coroutine
6883
else:
69-
return asyncio.run_coroutine_threadsafe(consume_generator(coroutine), main_loop).result()
84+
return async_to_sync_gen(coroutine, main_loop, False)
7085

7186
setattr(obj, name, async_to_sync_wrap)
7287

0 commit comments

Comments
 (0)