added await
This commit is contained in:
parent
c952bd921f
commit
9e83da6b1a
@ -1,4 +1,5 @@
|
||||
import json
|
||||
import asyncio
|
||||
|
||||
def convert_to_bytes(size: int | str) -> int:
|
||||
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:
|
||||
size_left = size
|
||||
|
||||
# https://github.com/tiangolo/fastapi/issues/5183
|
||||
# https://github.com/encode/starlette/discussions/1776#discussioncomment-3207518
|
||||
|
||||
try:
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user