How to wait for execution of another electron#

Let’s say we need to wait for a task (task_A) to finish execution before we start a different task (task_B) but none of the outputs of task_A are inputs to task_B.

For this purpose, there exists a method called wait_for() in the electron which takes as input the tasks to wait for before executing this one. It can be used as follows:

[1]:

import covalent as ct

@ct.electron
import time
time.sleep(3)
return a ** 2

@ct.electron
return x * y

@ct.electron
return b ** 3

@ct.lattice
def workflow():

result = ct.dispatch_sync(workflow)()
print(result.result)

1500


Here, task_3 is going to wait for completion of task_1 even though task_3’s execution does not directly depend on task_1’s output.

You can also pass in a list of tasks to wait for:

[2]:

import covalent as ct
import time

@ct.electron
time.sleep(1)
return a ** 2

@ct.electron
time.sleep(1)
return a ** 3

@ct.electron
time.sleep(1)
return a ** 4

@ct.electron
return x * y

@ct.electron
return b ** 3

@ct.lattice
def workflow():

1500

wait_for is especially useful when the dependent task does not take any inputs but still needs to wait for some other tasks, which may not return an output, to finish before starting its own execution.