4444
4545
4646@hookimpl
47- def pytask_execute_build (session : Session ) -> bool | None : # noqa: C901, PLR0915
47+ def pytask_execute_build (session : Session ) -> bool | None : # noqa: C901, PLR0912, PLR0915
4848 """Execute tasks with a parallel backend.
4949
5050 There are three phases while the scheduler has tasks which need to be executed.
@@ -75,6 +75,7 @@ def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR091
7575
7676 # Get the live execution manager from the registry if it exists.
7777 live_execution = session .config ["pm" ].get_plugin ("live_execution" )
78+ any_coiled_task = any (is_coiled_function (task ) for task in session .tasks )
7879
7980 # The executor can only be created after the collection to give users the
8081 # possibility to inject their own executors.
@@ -93,7 +94,26 @@ def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR091
9394 while session .scheduler .is_active ():
9495 try :
9596 newly_collected_reports = []
96- ready_tasks = list (session .scheduler .get_ready (10_000 ))
97+
98+ # If there is any coiled function, the user probably wants to exploit
99+ # adaptive scaling. Thus, we need to submit all ready tasks.
100+ # Unfortunately, all submitted tasks are shown as running although some
101+ # are pending.
102+ #
103+ # Without coiled functions, we submit as many tasks as there are
104+ # available workers since we cannot reliably detect a pending status.
105+ #
106+ # See #98 for more information.
107+ if any_coiled_task :
108+ n_new_tasks = 10_000
109+ else :
110+ n_new_tasks = session .config ["n_workers" ] - len (running_tasks )
111+
112+ ready_tasks = (
113+ list (session .scheduler .get_ready (n_new_tasks ))
114+ if n_new_tasks >= 1
115+ else []
116+ )
97117
98118 for task_signature in ready_tasks :
99119 task = session .dag .nodes [task_signature ]["task" ]
0 commit comments