Skip to content

Instantly share code, notes, and snippets.

@timothymugayi
Last active March 5, 2020 09:14
Show Gist options
  • Save timothymugayi/abc67d7f4d0b0526555cd707b0582406 to your computer and use it in GitHub Desktop.
Save timothymugayi/abc67d7f4d0b0526555cd707b0582406 to your computer and use it in GitHub Desktop.
import random
import time
from dask.distributed import Client
def inc(x: int) -> int:
time.sleep(random.randrange(1, 2, 1))
return x + 1
def double(x: int) -> int:
time.sleep(random.randrange(1, 2, 1))
return 2 * x
def add(x: int, y: int) -> int:
time.sleep(random.randrange(1, 2, 1))
return x + y
def dont_exit():
while True:
time.sleep(1)
print("done waiting exit....")
if __name__ == '__main__':
client = Client(threads_per_worker=4, n_workers=1)
zs = []
for i in range(10):
x = client.submit(inc, i) # x = inc(i)
y = client.submit(double, x) # y = inc(x)
z = client.submit(add, x, y) # z = inc(y)
zs.append(z)
total = client.submit(sum, zs)
print("Total = {}".format(total.result()))
dont_exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment