File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -172,7 +172,12 @@ async def start(self):
172172 context = dask_setup .make_context (
173173 "dask_setup" , list (self .argv ), allow_extra_args = False
174174 )
175- dask_setup .callback (self .dask_server , * context .args , ** context .params )
175+ result = dask_setup .callback (
176+ self .dask_server , * context .args , ** context .params
177+ )
178+ if inspect .isawaitable (result ):
179+ await result
180+ logger .info ("Run preload setup click command: %s" , self .name )
176181 else :
177182 future = dask_setup (self .dask_server )
178183 if inspect .isawaitable (future ):
Original file line number Diff line number Diff line change @@ -106,6 +106,36 @@ def check_worker():
106106 shutil .rmtree (tmpdir )
107107
108108
109+ @pytest .mark .asyncio
110+ async def test_worker_preload_click (cleanup , tmpdir ):
111+ CLICK_PRELOAD_TEXT = """
112+ import click
113+
114+ @click.command()
115+ def dask_setup(worker):
116+ worker.foo = 'setup'
117+ """
118+ async with Scheduler (port = 0 ) as s :
119+ async with Worker (s .address , preload = CLICK_PRELOAD_TEXT ) as w :
120+ assert w .foo == "setup"
121+
122+
123+ @pytest .mark .asyncio
124+ async def test_worker_preload_click_async (cleanup , tmpdir ):
125+ # Ensure we allow for click commands wrapping coroutines
126+ # https://github.com/dask/distributed/issues/4169
127+ CLICK_PRELOAD_TEXT = """
128+ import click
129+
130+ @click.command()
131+ async def dask_setup(worker):
132+ worker.foo = 'setup'
133+ """
134+ async with Scheduler (port = 0 ) as s :
135+ async with Worker (s .address , preload = CLICK_PRELOAD_TEXT ) as w :
136+ assert w .foo == "setup"
137+
138+
109139@pytest .mark .asyncio
110140async def test_preload_import_time (cleanup ):
111141 text = """
You can’t perform that action at this time.
0 commit comments