aiodocker
#广州# OSC源创会第31期(12月27日)开始报名,OSC自曝家丑!
aiodocker —— AsyncIO bindings for docker.io
示例代码:
#!/usr/bin/env python3import asynciofrom aiodocker.docker import Dockerloop = asyncio.get_event_loop()docker = Docker("http://localhost:4243/")@asyncio.coroutinedef handler(events): queue = events.listen() container = yield from docker.containers.run(config, name='testing') while True: event = yield from queue.get() if event['status'] == 'create': yield from event['container'].stop() print("Killed {id} so hard".format(**event))events = docker.eventstasks = [asyncio.async(events.run()), asyncio.async(handler(events)),]loop.run_until_complete(asyncio.gather(*tasks))