def test_launch_with_coroutine(): default_launcher = DefaultLauncher() launch_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py') launch_descriptor = LaunchDescriptor() load_launch_file(launch_file, launch_descriptor, {}) @asyncio.coroutine def coroutine(): yield from asyncio.sleep(1) print('one', file=sys.stderr) yield from asyncio.sleep(1) print('two', file=sys.stderr) yield from asyncio.sleep(1) print('three', file=sys.stderr) @asyncio.coroutine def coroutine2(): yield from asyncio.sleep(1) print('one mississippi', file=sys.stderr) yield from asyncio.sleep(1) print('two mississippi', file=sys.stderr) yield from asyncio.sleep(1) print('three mississippi', file=sys.stderr) launch_descriptor.add_coroutine( coroutine(), name='coroutine', exit_handler=primary_exit_handler) # launch_descriptor.add_coroutine(coroutine2()) print('launch', file=sys.stderr) default_launcher.add_launch_descriptor(launch_descriptor) rc = default_launcher.launch() print('done', rc, file=sys.stderr)
def test_launch_with_coroutine(): default_launcher = DefaultLauncher() launch_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py') launch_descriptor = LaunchDescriptor() load_launch_file(launch_file, launch_descriptor, {}) async def coroutine(): await asyncio.sleep(1) print('one', file=sys.stderr) await asyncio.sleep(1) print('two', file=sys.stderr) await asyncio.sleep(1) print('three', file=sys.stderr) async def coroutine2(): await asyncio.sleep(1) print('one mississippi', file=sys.stderr) await asyncio.sleep(1) print('two mississippi', file=sys.stderr) await asyncio.sleep(1) print('three mississippi', file=sys.stderr) launch_descriptor.add_coroutine(coroutine(), name='coroutine', exit_handler=primary_exit_handler) # launch_descriptor.add_coroutine(coroutine2()) print('launch', file=sys.stderr) default_launcher.add_launch_descriptor(launch_descriptor) rc = default_launcher.launch() print('done', rc, file=sys.stderr)
def setup(): global async_launcher default_launcher = DefaultLauncher() launch_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py') launch_descriptor = LaunchDescriptor() load_launch_file(launch_file, launch_descriptor, {}) default_launcher.add_launch_descriptor(launch_descriptor) async_launcher = AsynchronousLauncher(default_launcher) async_launcher.start()
def launch(launch_descriptor, argv): counter_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'counter.py') with NamedTemporaryFile(mode='w', prefix='foo_', delete=False) as h: foo_filename = h.name with NamedTemporaryFile(mode='w', prefix='baz-err_', delete=False) as h: baz_filename = h.name ld = launch_descriptor ld.add_process( cmd=[ sys.executable, '-u', counter_file, '--limit', '9', '--sleep', '0.5' ], name='foo', output_handlers=[FileOutput(filename=foo_filename)], exit_handler=restart_exit_handler, ) ld.add_process( cmd=[ sys.executable, '-u', counter_file, '--limit', '10', '--sleep', '0.25' ], name='bar', env=None, exit_handler=ignore_exit_handler, ) ld.add_process( cmd=[ sys.executable, '-u', counter_file, '--limit', '5', '--sleep', '1' ], name='baz', output_handlers=[FileOutput(filename_stderr=baz_filename)], ) ld.add_process( cmd=[sys.executable, '-u', counter_file, '--sleep', '0.5'], name='qux', output_handlers=[ConsoleOutput(stderr_only=True)], ) other_launch_file = os.path.join( os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py') sub_ld = LaunchDescriptor() load_launch_file(other_launch_file, sub_ld, {}) # namespace all processes from other launch file for d in sub_ld.task_descriptors: d.name = 'sub.' + d.name ld.task_descriptors.append(d)
def main(argv=sys.argv[1:]): parser = argparse.ArgumentParser( description='Launch the processes specified in a launch file.') parser.add_argument('launch_file', type=file_exists, nargs='+', help='The launch file.') args = parser.parse_args(argv) arguments = {} launcher = DefaultLauncher() for launch_file in args.launch_file: launch_descriptor = LaunchDescriptor() load_launch_file(launch_file, launch_descriptor, arguments) launcher.add_launch_descriptor(launch_descriptor) rc = launcher.launch() return rc
def main(argv=sys.argv[1:]): parser = argparse.ArgumentParser( description='Launch the processes specified in a launch file.') parser.add_argument( 'launch_file', type=file_exists, nargs='+', help='The launch file.') args = parser.parse_args(argv) arguments = {} launcher = DefaultLauncher() for launch_file in args.launch_file: launch_descriptor = LaunchDescriptor() load_launch_file(launch_file, launch_descriptor, arguments) launcher.add_launch_descriptor(launch_descriptor) rc = launcher.launch() return rc
def launch(launch_descriptor, argv): counter_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'counter.py') with NamedTemporaryFile(mode='w', prefix='foo_', delete=False) as h: foo_filename = h.name with NamedTemporaryFile(mode='w', prefix='baz-err_', delete=False) as h: baz_filename = h.name ld = launch_descriptor ld.add_process( cmd=[sys.executable, '-u', counter_file, '--limit', '9', '--sleep', '0.5'], name='foo', output_handlers=[FileOutput(filename=foo_filename)], exit_handler=restart_exit_handler, ) ld.add_process( cmd=[sys.executable, '-u', counter_file, '--limit', '10', '--sleep', '0.25'], name='bar', env=None, exit_handler=ignore_exit_handler, ) ld.add_process( cmd=[sys.executable, '-u', counter_file, '--limit', '5', '--sleep', '1'], name='baz', output_handlers=[FileOutput(filename_stderr=baz_filename)], ) ld.add_process( cmd=[sys.executable, '-u', counter_file, '--sleep', '0.5'], name='qux', output_handlers=[ConsoleOutput(stderr_only=True)], ) other_launch_file = os.path.join( os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py') sub_ld = LaunchDescriptor() load_launch_file(other_launch_file, sub_ld, {}) # namespace all processes from other launch file for d in sub_ld.task_descriptors: d.name = 'sub.' + d.name ld.task_descriptors.append(d)
def main(argv=sys.argv[1:]): parser = argparse.ArgumentParser( description='Launch the processes specified in a launch file.') parser.add_argument('launch_file', type=file_exists, nargs='+', help='The launch file.') parser.add_argument( '--args', metavar='arg', type=str, nargs='+', help='An argument to the launch file (e.g., arg_name:=value). All ' 'arguments will be passed to each launch file.') args = parser.parse_args(argv) launcher = DefaultLauncher() for launch_file in args.launch_file: launch_descriptor = LaunchDescriptor() load_launch_file(launch_file, launch_descriptor, args.args) launcher.add_launch_descriptor(launch_descriptor) rc = launcher.launch() return rc