Skip to content

Instantly share code, notes, and snippets.

@ChengzhiZhao
Last active April 4, 2020 01:08
Show Gist options
  • Select an option

  • Save ChengzhiZhao/2c0e7e609279499172a7b58724b29608 to your computer and use it in GitHub Desktop.

Select an option

Save ChengzhiZhao/2c0e7e609279499172a7b58724b29608 to your computer and use it in GitHub Desktop.
Dask_Delayed
import dask
import dask.dataframe as dd
import time
from dask.distributed import Client, progress
client = Client(threads_per_worker=2, n_workers=2)
client
def call_api():
time.sleep(1)
start_time = time.time()
for i in range(3):
call_api()
# Should be 3 seconds
print("--- %s seconds ---" % (time.time() - start_time))
# Let's compute them in Parallel
dask_call_api = dask.delayed(call_api)
zs = []
for i in range(3):
zs.append(dask_call_api())
start_time = time.time()
dd.compute(*zs)
print("--- %s seconds ---" % (time.time() - start_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment