Add basic doctest(ed) executor examples
Change-Id: I8940fe16299b02ec4d92479e06c884a72f401cec
This commit is contained in:
parent
cba2ef8169
commit
3d9ec12833
|
@ -22,7 +22,7 @@ sys.path.insert(0, os.path.abspath('../..'))
|
|||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
#'sphinx.ext.intersphinx',
|
||||
'sphinx.ext.doctest',
|
||||
'oslosphinx'
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
========
|
||||
Examples
|
||||
========
|
||||
|
||||
-----------------------------------------
|
||||
Creating and using a synchronous executor
|
||||
-----------------------------------------
|
||||
|
||||
.. testcode::
|
||||
|
||||
import time
|
||||
|
||||
import futurist
|
||||
|
||||
def delayed_func():
|
||||
time.sleep(0.1)
|
||||
return "hello"
|
||||
|
||||
e = futurist.SynchronousExecutor()
|
||||
fut = e.submit(delayed_func)
|
||||
print(fut.result())
|
||||
e.shutdown()
|
||||
|
||||
**Expected output:**
|
||||
|
||||
.. testoutput::
|
||||
|
||||
hello
|
||||
|
||||
|
||||
------------------------------------------
|
||||
Creating and using a thread-based executor
|
||||
------------------------------------------
|
||||
|
||||
.. testcode::
|
||||
|
||||
import time
|
||||
|
||||
import futurist
|
||||
|
||||
def delayed_func():
|
||||
time.sleep(0.1)
|
||||
return "hello"
|
||||
|
||||
e = futurist.ThreadPoolExecutor()
|
||||
fut = e.submit(delayed_func)
|
||||
print(fut.result())
|
||||
e.shutdown()
|
||||
|
||||
**Expected output:**
|
||||
|
||||
.. testoutput::
|
||||
|
||||
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
|
||||
-------------------------------------------
|
||||
|
||||
.. testcode::
|
||||
|
||||
import time
|
||||
|
||||
import futurist
|
||||
|
||||
def delayed_func():
|
||||
time.sleep(0.1)
|
||||
return "hello"
|
||||
|
||||
e = futurist.ProcessPoolExecutor()
|
||||
fut = e.submit(delayed_func)
|
||||
print(fut.result())
|
||||
e.shutdown()
|
||||
|
||||
**Expected output:**
|
||||
|
||||
.. testoutput::
|
||||
|
||||
hello
|
|
@ -9,6 +9,7 @@ Code from the future, delivered to you in the **now**.
|
|||
features
|
||||
api
|
||||
installation
|
||||
examples
|
||||
contributing
|
||||
|
||||
Indices and tables
|
||||
|
|
Loading…
Reference in New Issue