In [1]:
import os, sys
sys.path.append(os.path.abspath('../../main/python'))
In [2]:
import math
import time
import thalesians.tsa.evaluation as evaluation
In [3]:
def fact(x):
time.sleep(10)
return math.factorial(x)
In [4]:
current_thread_evaluator = evaluation.CurrentThreadEvaluator()
In [5]:
status = evaluation.evaluate(fact, args=[10], evaluator=current_thread_evaluator)
print(status)
For the following to work, you need to run (for example)
ipcluster is usually located in the Scripts directory of your Python distribution. If it is missing, you need to install the ipyparallel package, either using the Anaconda Navigator, or pip install ipyparallel
, or conda install ipyparallel
.
Also note that, for the following to work, this library must me on ipcluster
's PYTHONPATH
. Thus, for example, you would need to
(correct the above for your operating system and directory structure) before launching ipcluster
with the above command.
In [6]:
ipp_evaluator = evaluation.IPyParallelEvaluator()
In [7]:
status1 = evaluation.evaluate(fact, args=[10], evaluator=ipp_evaluator)
print(status1)
In [8]:
status2 = evaluation.evaluate(fact, args=[8], evaluator=ipp_evaluator)
print(status2)
In [9]:
def my_callback(status):
print('The status is now ready:', status)
status3 = evaluation.evaluate(fact, args=[8], evaluator=ipp_evaluator)
status3.add_callback(my_callback)
In [10]:
status1
Out[10]:
In [11]:
status2
Out[11]:
In [12]:
status3
Out[12]:
In [13]:
statuses = []
for x in range(25):
status = evaluation.evaluate(fact, args=[x], evaluator=ipp_evaluator)
print(status)
statuses.append(status)
In [14]:
statuses[24]
Out[14]:
In [15]:
statuses[24]
Out[15]: