This commit is contained in:
x03daop
2015-09-01 10:09:12 +02:00
parent e104c934af
commit f3c57cbe5a
26 changed files with 789 additions and 11 deletions

View File

@@ -0,0 +1,51 @@
"""
Using Pararellization API to execute tasks concurrently
"""
import traceback
#Simple parallization
def task1():
m1.moveRel(1.0)
return m1.getPosition()
def task2():
m2.moveRel(1.0)
return m1.getPosition()
def task3():
return ai1.read()
ret = parallelize(task1, task2, task3)
print ret
#Fork amd join
ret = fork(task1, task2, task3)
print ai1.read()
ret = join(ret)
print ret
#Functions with parameters
def moveRelative(motor, step):
print "Moving " + motor.getName() + " step = " + str(step)
motor.moveRel(step)
return motor.getPosition()
ret = parallelize((moveRelative,(m1,-2)), (moveRelative,(m2,-2)))
print ret
#Exception in parallel task is thrown back to script
try:
parallelize((moveRelative,(ai1,1)), (moveRelative,(ai2,1)))
except:
print "Ok, caught exception:"
traceback.print_exc()