Created
August 22, 2016 11:59
-
-
Save mgedmin/20bb3265ede4d35203f3833ef6353352 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import asyncio.subprocess | |
import signal | |
import sys | |
@asyncio.coroutine | |
def run_in_background(*command, prefix): | |
proc = yield from asyncio.create_subprocess_exec(*command, | |
stdout=asyncio.subprocess.PIPE, | |
stderr=asyncio.subprocess.STDOUT) | |
while True: | |
line = yield from proc.stdout.readline() | |
if not line: | |
break | |
print("{}: {}".format(prefix, line.rstrip().decode('UTF-8'))) | |
yield from proc.wait() | |
@asyncio.coroutine | |
def run_server(): | |
yield from run_in_background('make', 'run-server', prefix='SERVER') | |
@asyncio.coroutine | |
def run_client(): | |
yield from run_in_background('make', 'run-client', prefix='CLIENT') | |
@asyncio.coroutine | |
def run_robot(): | |
yield from run_in_background('make', 'headless-robot', prefix='ROBOT') | |
@asyncio.coroutine | |
def robot_tests(): | |
server = asyncio.ensure_future(run_server()) | |
client = asyncio.ensure_future(run_client()) | |
robot = asyncio.ensure_future(run_robot()) | |
rc = yield from robot | |
def main(): | |
try: | |
loop = asyncio.get_event_loop() | |
loop.add_signal_handler(signal.SIGINT, loop.stop) | |
loop.add_signal_handler(signal.SIGTERM, loop.stop) | |
rc = loop.run_until_complete(robot_tests()) | |
except KeyboardInterrupt: | |
sys.exit(2) | |
else: | |
sys.exit(rc) | |
finally: | |
loop.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment