Startup
This commit is contained in:
51
script/tutorial/15_Pararellization.py
Normal file
51
script/tutorial/15_Pararellization.py
Normal 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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user