@@ -36,6 +36,7 @@ class Worker(metaclass=abc.ABCMeta):
3636 """A base class for execution of tasks."""
3737
3838 plugin_name : str
39+ loop : asyncio .AbstractEventLoop
3940
4041 def __init__ (self , loop = None ):
4142 """Initialize the worker."""
@@ -48,10 +49,11 @@ def run(self, task: "Task[DefType]", rerun: bool = False) -> "Result":
4849 pass
4950
5051 async def run_async (self , task : "Task[DefType]" , rerun : bool = False ) -> "Result" :
51- if task .is_async :
52+ if task .is_async : # only for workflows at this stage and the foreseeable
53+ # These jobs are run in the primary process but farm out the workflows jobs
5254 return await task .run_async (rerun = rerun )
5355 else :
54- return task .run (rerun = rerun )
56+ return self .run (task = task , rerun = rerun )
5557
5658 def close (self ):
5759 """Close this worker."""
@@ -175,7 +177,8 @@ class ConcurrentFuturesWorker(Worker):
175177 plugin_name = "cf"
176178
177179 n_procs : int
178- loop : cf .ProcessPoolExecutor
180+ loop : asyncio .AbstractEventLoop
181+ pool : cf .ProcessPoolExecutor
179182
180183 def __init__ (self , n_procs : int | None = None ):
181184 """Initialize Worker."""
@@ -193,13 +196,12 @@ async def run(
193196 ) -> "Result" :
194197 """Run a task."""
195198 assert self .loop , "No event loop available to submit tasks"
196- task_pkl = cp .dumps (task )
197199 return await self .loop .run_in_executor (
198- self .pool , self .unpickle_and_run , task_pkl , rerun
200+ self .pool , self .uncloudpickle_and_run , cp . dumps ( task ) , rerun
199201 )
200202
201203 @classmethod
202- def unpickle_and_run (cls , task_pkl : Path , rerun : bool ) -> "Result" :
204+ def uncloudpickle_and_run (cls , task_pkl : bytes , rerun : bool ) -> "Result" :
203205 """Unpickle and run a task."""
204206 task : Task [DefType ] = cp .loads (task_pkl )
205207 return task .run (rerun = rerun )
0 commit comments