3737
3838if TYPE_CHECKING :
3939 from collections .abc import Callable
40+ from queue import Queue
4041 from types import TracebackType
4142
4243 from pytask import Mark
@@ -58,7 +59,11 @@ class WrapperResult:
5859
5960
6061def wrap_task_in_thread (
61- task : PTask , * , remote : bool , shared_memory : dict [str , bool ] | None , ** kwargs : Any
62+ task : PTask ,
63+ * ,
64+ remote : bool ,
65+ status_queue : "Queue[str] | None" = None ,
66+ ** kwargs : Any ,
6267) -> WrapperResult :
6368 """Mock execution function such that it returns the same as for processes.
6469
@@ -69,9 +74,9 @@ def wrap_task_in_thread(
6974 """
7075 __tracebackhide__ = True
7176
72- # Add task to shared memory to indicate that it is currently being executed.
73- if shared_memory is not None :
74- shared_memory [ task .signature ] = True
77+ # Add task to the status queue to indicate that it is currently being executed.
78+ if status_queue is not None :
79+ status_queue . put ( task .signature )
7580
7681 try :
7782 out = task .function (** kwargs )
@@ -89,9 +94,6 @@ def wrap_task_in_thread(
8994 _handle_function_products (task , out , remote = remote )
9095 exc_info = None
9196
92- # Remove task from shared memory to indicate that it is no longer being executed.
93- if shared_memory is not None :
94- shared_memory .pop (task .signature , None )
9597 return WrapperResult (
9698 carry_over_products = None ,
9799 warning_reports = [],
@@ -108,7 +110,7 @@ def wrap_task_in_process( # noqa: PLR0913
108110 kwargs : dict [str , Any ],
109111 remote : bool ,
110112 session_filterwarnings : tuple [str , ...],
111- shared_memory : dict [str , bool ] | None ,
113+ status_queue : "Queue [str] | None" = None ,
112114 show_locals : bool ,
113115 task_filterwarnings : tuple [Mark , ...],
114116) -> WrapperResult :
@@ -121,9 +123,9 @@ def wrap_task_in_process( # noqa: PLR0913
121123 # Hide this function from tracebacks.
122124 __tracebackhide__ = True
123125
124- # Add task to shared memory to indicate that it is currently being executed.
125- if shared_memory is not None :
126- shared_memory [ task .signature ] = True
126+ # Add task to the status queue to indicate that it is currently being executed.
127+ if status_queue is not None :
128+ status_queue . put ( task .signature )
127129
128130 # Patch set_trace and breakpoint to show a better error message.
129131 _patch_set_trace_and_breakpoint ()
@@ -184,10 +186,6 @@ def wrap_task_in_process( # noqa: PLR0913
184186 captured_stdout_buffer .close ()
185187 captured_stderr_buffer .close ()
186188
187- # Remove task from shared memory to indicate that it is no longer being executed.
188- if shared_memory is not None :
189- shared_memory .pop (task .signature , None )
190-
191189 return WrapperResult (
192190 carry_over_products = products ,
193191 warning_reports = warning_reports ,
0 commit comments