log.info('creating executor tasks') loop = asyncio.get_event_loop() blocking_tasks = [ loop.run_in_executor(executor, blocks, i) for i inrange(6) ] log.info('waiting for executor tasks') completed, pending = await asyncio.wait(blocking_tasks) results = [t.result() for t in completed] log.info('results: {!r}'.format(results))
log.info('exiting')
if __name__ == '__main__': # Configure logging to show the name of the thread # where the log message originates. logging.basicConfig( level=logging.INFO, format='%(threadName)10s %(name)18s: %(message)s', stream=sys.stderr, )
# Create a limited thread pool. executor = concurrent.futures.ThreadPoolExecutor( max_workers=3, )
# asyncio_executor_process.py # changes from asyncio_executor_thread.py
if __name__ == '__main__': # Configure logging to show the id of the process # where the log message originates. logging.basicConfig( level=logging.INFO, format='PID %(process)5s %(name)18s: %(message)s', stream=sys.stderr, )
# Create a limited process pool. executor = concurrent.futures.ProcessPoolExecutor( max_workers=3, )