Pass a string as executor in the example instead of an executor

Instead of creating a throw-away executor and then passing it to the
engine for usage there just pass a string that specifies that we want
the executor created/used to be process based and let the engine handle
the creation and shutdown of that executor on its own.

Change-Id: Ib9cdbe50d1a12ec8b5bec86531f76ef51926645c
This commit is contained in:
Joshua Harlow
2015-01-09 12:58:58 -08:00
parent 316b453558
commit a588e48463

View File

@@ -22,8 +22,6 @@ import string
import sys
import time
from concurrent import futures
logging.basicConfig(level=logging.ERROR)
self_dir = os.path.abspath(os.path.dirname(__file__))
@@ -46,12 +44,7 @@ from taskflow import task
# This is useful since it allows further scaling up your workflows when thread
# execution starts to become a bottleneck (which it can start to be due to the
# GIL in python). It also offers a intermediary scalable runner that can be
# used when the scale and or setup of remote workers is not desirable.
# How many local processes to potentially use when executing... (one is fine
# for this example, but more can be used to show play around with what happens
# with many...)
WORKERS = 1
# used when the scale and/or setup of remote workers is not desirable.
def progress_printer(task, event_type, details):
@@ -87,15 +80,14 @@ for letter in string.ascii_lowercase:
functools.partial(progress_printer, abc))
soup.add(abc)
try:
with futures.ProcessPoolExecutor(WORKERS) as executor:
print("Loading...")
e = engines.load(soup, engine='parallel', executor=executor)
print("Compiling...")
e.compile()
print("Preparing...")
e.prepare()
print("Running...")
e.run()
print("Done...")
print("Loading...")
e = engines.load(soup, engine='parallel', executor='processes')
print("Compiling...")
e.compile()
print("Preparing...")
e.prepare()
print("Running...")
e.run()
print("Done...")
except exceptions.NotImplementedError as e:
print(e)