diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-23 00:22:44 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-23 00:22:44 +0300 |
| commit | a96b13f6816ca0657d9f65097b97d0e87e1a0366 (patch) | |
| tree | 44e0ac5eda49f7c4353c482d7d61ba4a6de68afd /src/socks.py | |
| parent | a9db8ca9e4dc64e196fbb095939f3bfbeb659696 (diff) | |
| download | httpy-a96b13f6816ca0657d9f65097b97d0e87e1a0366.tar.gz httpy-a96b13f6816ca0657d9f65097b97d0e87e1a0366.zip | |
Ditch asyncio, threading actually works much better
Problem was that I wanted to do things actually in parallel, and wanted to launch a task but without blocking the thread, asyncio was for whatever reason blocking the thread which was causing issues when 1 user was downloading a file and trying to do something else on the page (like load a new page or something) Threading ACTUALLY does do exactly what I want via `threading.Thread(...).start()`, so that will be used going forward Also, it seems to 3x faster that way, because with asyncio the page took 1 sec to load, with threading it takes 280 ms, which is weird even if we are doing things one at a time
Diffstat (limited to 'src/socks.py')
| -rw-r--r-- | src/socks.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/socks.py b/src/socks.py index bcb76c0..4e7d2ea 100644 --- a/src/socks.py +++ b/src/socks.py @@ -1,23 +1,19 @@ -import asyncio +from time import sleep from ssl import SSLSocket _SOCK_TIME_DELAY = 1.e-3 -async def ssl_sock_accept(sock: SSLSocket) -> tuple[SSLSocket, str]: +def ssl_sock_accept(sock: SSLSocket) -> tuple[SSLSocket, str]: while True: try: return sock.accept() except BlockingIOError: - await asyncio.sleep(_SOCK_TIME_DELAY) + sleep(_SOCK_TIME_DELAY) -async def ssl_sock_recv(sock: SSLSocket, buflen: int = 1024): +def ssl_sock_recv(sock: SSLSocket, buflen: int = 1024): while (msg := sock.recv(buflen)) == b'': - await asyncio.sleep(_SOCK_TIME_DELAY) + sleep(_SOCK_TIME_DELAY) return msg - - -async def ssl_sock_sendall(sock: SSLSocket, data: bytes): - sock.sendall(data) |