From f47aaa5195653d65e8010eac83598e73fd9120f6 Mon Sep 17 00:00:00 2001 From: Mia von Steinkirch Date: Fri, 6 Mar 2020 01:16:17 -0800 Subject: [PATCH] post done --- Concurrence_examples/asyncio_simple_example.py | 15 +++++++++++++++ Concurrence_examples/threadpool_example.py | 2 +- Concurrence_examples/threads_with_queues.py | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 Concurrence_examples/asyncio_simple_example.py diff --git a/Concurrence_examples/asyncio_simple_example.py b/Concurrence_examples/asyncio_simple_example.py new file mode 100644 index 0000000..3c2a508 --- /dev/null +++ b/Concurrence_examples/asyncio_simple_example.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +import asyncio + +async def delayed_hello(): + print("Hello ") + await asyncio.sleep(1) + print("World!") + + +if __name__ == "__main__": + + loop = asyncio.get_event_loop() + loop.run_until_complete(delayed_hello()) + loop.close() \ No newline at end of file diff --git a/Concurrence_examples/threadpool_example.py b/Concurrence_examples/threadpool_example.py index a48e021..242c323 100644 --- a/Concurrence_examples/threadpool_example.py +++ b/Concurrence_examples/threadpool_example.py @@ -9,9 +9,9 @@ def return_after_5_secs(message): return message pool = ThreadPoolExecutor(3) - future = pool.submit(return_after_5_secs, ("hello")) + print(future.done()) sleep(5) print(future.done()) diff --git a/Concurrence_examples/threads_with_queues.py b/Concurrence_examples/threads_with_queues.py index 5d30095..921b144 100644 --- a/Concurrence_examples/threads_with_queues.py +++ b/Concurrence_examples/threads_with_queues.py @@ -33,4 +33,4 @@ task_queue.join() end_time = time.time() -print("Time: %ssecs" % (end_time - start_time)) \ No newline at end of file +print('Time: {} secs'.format(end_time - start_time)) \ No newline at end of file