示例#1
0
    async def run_wsgi_feeder(self, scope: Scope, receive: Receive,
                              fut: Awaitable[None], input_io: BytesIO):
        while not fut.done():
            event = await receive()
            if event["type"] == "http.disconnect":
                input_io.close()
                break

            # Use exponential back-off until each attempt is 30 seconds apart.
            b = 0
            while len(input_io.getbuffer()) > 1024 * 1024:
                await asyncio.sleep(0.1 * (1.1**b))
                if b < 60:
                    b += 1

            input_io.write(event.get("body", b""))

            if not event.get("more_body", False):
                input_io.close()
                break