From 293c8a79650dbe46977fcdac5babb815c24ec2af Mon Sep 17 00:00:00 2001 From: penn5 Date: Thu, 16 Sep 2021 13:34:47 +0100 Subject: [PATCH] Use threads for factorization faster on pypy, probably slower otherwise --- telethon/network/authenticator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/telethon/network/authenticator.py b/telethon/network/authenticator.py index ea476207..023bd718 100644 --- a/telethon/network/authenticator.py +++ b/telethon/network/authenticator.py @@ -2,6 +2,8 @@ This module contains several functions that authenticate the client machine with Telegram's servers, effectively creating an authorization key. """ +import asyncio +import functools import os import time from hashlib import sha1 @@ -37,7 +39,10 @@ async def do_authentication(sender): pq = get_int(res_pq.pq) # Step 2 sending: DH Exchange - p, q = Factorization.factorize(pq) + p, q = await asyncio.get_event_loop().run_in_executor( + None, + functools.partial(Factorization.factorize, pq) + ) p, q = rsa.get_byte_array(p), rsa.get_byte_array(q) new_nonce = int.from_bytes(os.urandom(32), 'little', signed=True)