
#Simple parallization
def task1():
    return out.read()

def task2():
    return inp.read()

def task3():
    time.sleep(0.1)
    return sin.read()

ret = parallelize(task1, task2, task3)
print ret


#Fork amd join
ret = fork(task1, task2, task3)
time.sleep(0.1)
ret = join(ret)
print ret


#Functions with parameters
def devRead(dev, msg):
    print msg + " -> " + dev.getName()
    return dev.read()

ret = parallelize((devRead,(out,"1")), (devRead,(inp,"2")), (devRead,(sin,"3")))
print ret


#Exception in parallel task
def taskExcept(msg):
    raise Exception ("Error in parallel task " + msg)


ret = parallelize((taskExcept,("1")), (taskExcept,(inp,"2")) )
print ret



