Last active
April 4, 2020 01:08
-
-
Save ChengzhiZhao/2c0e7e609279499172a7b58724b29608 to your computer and use it in GitHub Desktop.
Dask_Delayed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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