Skip to content

Commit

Permalink
Merge pull request #313 from jo-mueller/re-use-client-on-multiple-runs
Browse files Browse the repository at this point in the history
Re use client on multiple runs
  • Loading branch information
jo-mueller authored Jul 15, 2023
2 parents 0730300 + 2eb4672 commit 992291f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/napari_stress/_tests/test_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ def test_reconstruction(make_napari_viewer):

results = reconstruction.reconstruct_droplet(
image,
voxelsize=np.asarray([1.93, 1, 1]),
voxelsize=np.asarray([4, 2, 2]),
interpolation_method='linear',
target_voxelsize=1
target_voxelsize=2,
use_dask=True
)

for result in results:
Expand Down
10 changes: 7 additions & 3 deletions src/napari_stress/_utils/frame_by_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ def wrapper(*args, **kwargs):

# start dask cluster client
if use_dask:
client = Client()
print('Dask client up and running', client, f' Log: {client.dashboard_link}')
try:
client = get_client()
print('Dask client already running', client, f' Log: {client.dashboard_link}')
except ValueError:
client = Client()
print('Dask client up and running', client, f' Log: {client.dashboard_link}')
jobs = []

for t in frames:
Expand All @@ -61,14 +65,14 @@ def wrapper(*args, **kwargs):
_args[idx] = _args[idx][t]

if use_dask:
#args_futures = [client.scatter(arg) for arg in _args]
jobs.append(client.submit(function, *_args, **kwargs))
else:
results[t] = function(*_args, **kwargs)

if use_dask:
# gather results
results = client.gather(jobs)
client.close()

return converter.list_of_data_to_data(results, sig.return_annotation)
return wrapper
Expand Down

0 comments on commit 992291f

Please sign in to comment.