diff options
author | Yury Selivanov <yury@magic.io> | 2018-05-28 22:31:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-28 22:31:55 (GMT) |
commit | 7165754b6b5f3b7c07050d921fa1c58bba5f0ff1 (patch) | |
tree | a459d092b94d1c8e9498842192735f8486dd926e /Lib/asyncio/base_events.py | |
parent | 416c1ebd9896b394790dcb4f9f035b1a44ebe9ff (diff) | |
download | cpython-7165754b6b5f3b7c07050d921fa1c58bba5f0ff1.zip cpython-7165754b6b5f3b7c07050d921fa1c58bba5f0ff1.tar.gz cpython-7165754b6b5f3b7c07050d921fa1c58bba5f0ff1.tar.bz2 |
bpo-32410: Avoid blocking on file IO in sendfile fallback code (GH-7172)
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r-- | Lib/asyncio/base_events.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index a0243f5..ffd2513 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -800,7 +800,10 @@ class BaseEventLoop(events.AbstractEventLoop): async def _sock_sendfile_fallback(self, sock, file, offset, count): if offset: file.seek(offset) - blocksize = min(count, 16384) if count else 16384 + blocksize = ( + min(count, constants.SENDFILE_FALLBACK_READBUFFER_SIZE) + if count else constants.SENDFILE_FALLBACK_READBUFFER_SIZE + ) buf = bytearray(blocksize) total_sent = 0 try: @@ -810,7 +813,7 @@ class BaseEventLoop(events.AbstractEventLoop): if blocksize <= 0: break view = memoryview(buf)[:blocksize] - read = file.readinto(view) + read = await self.run_in_executor(None, file.readinto, view) if not read: break # EOF await self.sock_sendall(sock, view) |