How to use the aiodocker.jsonstream.json_stream_stream function in aiodocker

To help you get started, we’ve selected a few aiodocker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / aiodocker / aiodocker / images.py View on Github external
async def _handle_stream(self, cm):
        async with cm as response:
            async for item in json_stream_stream(response):
                yield item
github aio-libs / aiodocker / aiodocker / containers.py View on Github external
async def _stats_stream(self, cm):
        async with cm as response:
            async for item in json_stream_stream(response):
                yield item
github aio-libs / aiodocker / aiodocker / events.py View on Github external
Publish messages inside the asyncio queue.
        """
        if self.json_stream:
            warnings.warn("already running", RuntimeWarning, stackelevel=2)
            return
        forced_params = {"stream": True}
        params = ChainMap(forced_params, params)
        try:
            # timeout has to be set to 0, None is not passed
            # Otherwise after 5 minutes the client
            # will close the connection
            # http://aiohttp.readthedocs.io/en/stable/client_reference.html#aiohttp.ClientSession.request
            async with self.docker._query(
                "events", method="GET", params=params, timeout=0
            ) as response:
                self.json_stream = json_stream_stream(response, self._transform_event)
                try:
                    async for data in self.json_stream:
                        await self.channel.publish(data)
                finally:
                    if self.json_stream is not None:
                        await self.json_stream._close()
                    self.json_stream = None
        finally:
            # signal termination to subscribers
            await self.channel.publish(None)