added await
This commit is contained in:
parent
c952bd921f
commit
9e83da6b1a
19
src/utils.py
19
src/utils.py
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import asyncio
|
||||||
|
|
||||||
def convert_to_bytes(size: int | str) -> int:
|
def convert_to_bytes(size: int | str) -> int:
|
||||||
try:
|
try:
|
||||||
@ -23,11 +24,19 @@ def convert_to_bytes(size: int | str) -> int:
|
|||||||
async def generate_data(size: int, buffer_size: int = 4 * 1024) -> bytes:
|
async def generate_data(size: int, buffer_size: int = 4 * 1024) -> bytes:
|
||||||
size_left = size
|
size_left = size
|
||||||
|
|
||||||
while size_left > buffer_size:
|
# https://github.com/tiangolo/fastapi/issues/5183
|
||||||
size_left -= buffer_size
|
# https://github.com/encode/starlette/discussions/1776#discussioncomment-3207518
|
||||||
yield b'\0' * buffer_size
|
|
||||||
else:
|
try:
|
||||||
yield b'\0' * size_left
|
while size_left > buffer_size:
|
||||||
|
size_left -= buffer_size
|
||||||
|
yield b'\0' * buffer_size
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
else:
|
||||||
|
yield b'\0' * size_left
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
raise GeneratorExit
|
||||||
|
|
||||||
|
|
||||||
def check_policies(ip: str) -> None:
|
def check_policies(ip: str) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user