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_non_primary_return_code(): # since Python < 3.5 on Windows does not support signaling SIGINT to the subprocesses # we can't expect them to shutdown cleanly, therefore we ignore this test if os.name == 'nt': return default_launcher = DefaultLauncher() async def coroutine1(): await asyncio.sleep(1) print('one', file=sys.stderr) await asyncio.sleep(1) print('two', file=sys.stderr) return 3 async def coroutine2(): await asyncio.sleep(1) print('one mississippi', file=sys.stderr) return 0 launch_descriptor = LaunchDescriptor() launch_descriptor.add_coroutine(coroutine1(), name='coroutine1') launch_descriptor.add_coroutine( coroutine2(), name='coroutine2', exit_handler=primary_exit_handler) print('launch', file=sys.stderr) default_launcher.add_launch_descriptor(launch_descriptor) rc = default_launcher.launch() print('done', rc, file=sys.stderr) assert rc == 3, 'Expected return code is 3'
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 launch(index): default_launcher = DefaultLauncher() async def coroutine(): await asyncio.sleep(1) print('message %d' % index, file=sys.stderr) launch_descriptor = LaunchDescriptor() launch_descriptor.add_coroutine(coroutine(), name='coroutine%d' % index) print('launch %d' % index, file=sys.stderr) default_launcher.add_launch_descriptor(launch_descriptor) rc = default_launcher.launch() print('done %d' % index, rc, file=sys.stderr)