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
This commit is contained in:
Surojit Pathak 2016-01-14 01:45:42 +00:00
parent 4b452427f9
commit 7283021caf
1 changed files with 48 additions and 31 deletions

View File

@ -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
-------------------------------------------