From 7283021caf06c5606fd6384355212a66e631b81e Mon Sep 17 00:00:00 2001 From: Surojit Pathak Date: Thu, 14 Jan 2016 01:45:42 +0000 Subject: [PATCH] Modification of the example code To illustrate the fact that we can share code seemlessly with different scheduling behavior, at ease with futurist. Moreover, the example code shows how the concurrency/parallel execution can be observed from same code, just by changing the executor. This demonstrates the power of futurist interfaces. Change-Id: Ifdd2a89c8cd9d06f54900960a69debc41b42ab3d --- doc/source/examples.rst | 79 +++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/doc/source/examples.rst b/doc/source/examples.rst index 0a136c8..76350c5 100644 --- a/doc/source/examples.rst +++ b/doc/source/examples.rst @@ -8,24 +8,67 @@ Creating and using a synchronous executor .. testcode:: - import time + # NOTE: enable printing timestamp for additional data + import sys import futurist + import eventlet def delayed_func(): - time.sleep(0.1) - return "hello" + print("started") + eventlet.sleep(3) + print("done") + #print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) e = futurist.SynchronousExecutor() fut = e.submit(delayed_func) - print(fut.result()) + eventlet.sleep(1) + print("Hello") + eventlet.sleep(1) e.shutdown() + #print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) **Expected output:** .. testoutput:: - hello + started + done + Hello + +------------------------------------------------ +Creating and using a green thread-based executor +------------------------------------------------ + +.. testcode:: + + # NOTE: enable printing timestamp for additional data + + import sys + import futurist + import eventlet + + def delayed_func(): + print("started") + eventlet.sleep(3) + print("done") + + #print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + e = futurist.GreenThreadPoolExecutor() + fut = e.submit(delayed_func) + eventlet.sleep(1) + print("Hello") + eventlet.sleep(1) + e.shutdown() + #print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + +**Expected output:** + +.. testoutput:: + + started + Hello + done ------------------------------------------ @@ -53,32 +96,6 @@ Creating and using a thread-based executor hello ------------------------------------------------- -Creating and using a green thread-based executor ------------------------------------------------- - -.. testcode:: - - import time - - import futurist - - def delayed_func(): - time.sleep(0.1) - return "hello" - - e = futurist.GreenThreadPoolExecutor() - fut = e.submit(delayed_func) - print(fut.result()) - e.shutdown() - -**Expected output:** - -.. testoutput:: - - hello - - ------------------------------------------- Creating and using a process-based executor -------------------------------------------