def main(): args = get_argparser().parse_args() init_logger(args) if args.device is None: print("You need to supply a -d/--device " "argument. Use --help for more information.") sys.exit(1) loop = asyncio.get_event_loop() async def run(): with await Shutter.connect(args.device, loop=loop) as dev: server = Server({"ptb_shutter": dev}, None, True) await server.start(bind_address_from_args(args), args.port) try: await server.wait_terminate() finally: await server.stop() try: loop.run_until_complete(run()) except KeyboardInterrupt: pass finally: loop.close()
def main(): args = get_argparser().parse_args() init_logger(args) if os.name == "nt": asyncio.set_event_loop(asyncio.ProactorEventLoop()) loop = asyncio.get_event_loop() dev = OORS() async def run(): await dev.connect(args.uri, user=args.user, password=args.password) await dev.misc() server = Server({"oors": dev}, None, True) await server.start(bind_address_from_args(args), args.port) try: await server.wait_terminate() except KeyboardInterrupt: pass finally: await server.stop() loop.run_until_complete(run())