@@ -104,7 +104,7 @@ def revive_processes(processes: list[ProcessNode], *, wait: bool = False) -> Non
104
104
105
105
106
106
def play_processes (
107
- processes : list [ProcessNode ] | None = None , * , all_entries : bool = False , timeout : float = 5.0 , wait : bool = False
107
+ processes : list [ProcessNode ] | None = None , * , all_entries : bool = False , timeout : float = 5.0
108
108
) -> None :
109
109
"""Play (unpause) paused processes.
110
110
@@ -113,7 +113,6 @@ def play_processes(
113
113
:param processes: List of processes to play.
114
114
:param all_entries: Play all paused processes.
115
115
:param timeout: Raise a ``ProcessTimeoutException`` if the process does not respond within this amount of seconds.
116
- :param wait: Set to ``True`` to wait for process response, for ``False`` the action is fire-and-forget.
117
116
:raises ``ProcessTimeoutException``: If the processes do not respond within the timeout.
118
117
"""
119
118
if not get_daemon_client ().is_daemon_running :
@@ -130,7 +129,7 @@ def play_processes(
130
129
return
131
130
132
131
controller = get_manager ().get_process_controller ()
133
- _perform_actions (processes , controller .play_process , 'play' , 'playing' , timeout , wait )
132
+ _perform_actions (processes , controller .play_process , 'play' , 'playing' , timeout )
134
133
135
134
136
135
def pause_processes (
@@ -139,7 +138,6 @@ def pause_processes(
139
138
msg_text : str = 'Paused through `aiida.engine.processes.control.pause_processes`' ,
140
139
all_entries : bool = False ,
141
140
timeout : float = 5.0 ,
142
- wait : bool = False ,
143
141
) -> None :
144
142
"""Pause running processes.
145
143
@@ -148,7 +146,6 @@ def pause_processes(
148
146
:param processes: List of processes to play.
149
147
:param all_entries: Pause all playing processes.
150
148
:param timeout: Raise a ``ProcessTimeoutException`` if the process does not respond within this amount of seconds.
151
- :param wait: Set to ``True`` to wait for process response, for ``False`` the action is fire-and-forget.
152
149
:raises ``ProcessTimeoutException``: If the processes do not respond within the timeout.
153
150
"""
154
151
if not get_daemon_client ().is_daemon_running :
@@ -166,7 +163,7 @@ def pause_processes(
166
163
167
164
controller = get_manager ().get_process_controller ()
168
165
action = functools .partial (controller .pause_process , msg_text = msg_text )
169
- _perform_actions (processes , action , 'pause' , 'pausing' , timeout , wait )
166
+ _perform_actions (processes , action , 'pause' , 'pausing' , timeout )
170
167
171
168
172
169
def kill_processes (
@@ -176,7 +173,6 @@ def kill_processes(
176
173
force_kill : bool = False ,
177
174
all_entries : bool = False ,
178
175
timeout : float = 5.0 ,
179
- wait : bool = False ,
180
176
) -> None :
181
177
"""Kill running processes.
182
178
@@ -185,7 +181,6 @@ def kill_processes(
185
181
:param processes: List of processes to play.
186
182
:param all_entries: Kill all active processes.
187
183
:param timeout: Raise a ``ProcessTimeoutException`` if the process does not respond within this amount of seconds.
188
- :param wait: Set to ``True`` to wait for process response, for ``False`` the action is fire-and-forget.
189
184
:raises ``ProcessTimeoutException``: If the processes do not respond within the timeout.
190
185
"""
191
186
if not get_daemon_client ().is_daemon_running :
@@ -203,7 +198,7 @@ def kill_processes(
203
198
204
199
controller = get_manager ().get_process_controller ()
205
200
action = functools .partial (controller .kill_process , msg_text = msg_text , force_kill = force_kill )
206
- _perform_actions (processes , action , 'kill' , 'killing' , timeout , wait )
201
+ _perform_actions (processes , action , 'kill' , 'killing' , timeout )
207
202
208
203
209
204
def _perform_actions (
@@ -212,7 +207,6 @@ def _perform_actions(
212
207
infinitive : str ,
213
208
present : str ,
214
209
timeout : t .Optional [float ] = None ,
215
- wait : bool = False ,
216
210
** kwargs : t .Any ,
217
211
) -> None :
218
212
"""Perform an action on a list of processes.
@@ -223,7 +217,6 @@ def _perform_actions(
223
217
:param present: The present tense of the verb that represents the action.
224
218
:param past: The past tense of the verb that represents the action.
225
219
:param timeout: Raise a ``ProcessTimeoutException`` if the process does not respond within this amount of seconds.
226
- :param wait: Set to ``True`` to wait for process response, for ``False`` the action is fire-and-forget.
227
220
:param kwargs: Keyword arguments that will be passed to the method ``action``.
228
221
:raises ``ProcessTimeoutException``: If the processes do not respond within the timeout.
229
222
"""
@@ -241,77 +234,52 @@ def _perform_actions(
241
234
else :
242
235
futures [future ] = process
243
236
244
- _resolve_futures (futures , infinitive , present , wait , timeout )
237
+ _resolve_futures (futures , infinitive , present , timeout )
245
238
246
239
247
240
def _resolve_futures (
248
241
futures : dict [concurrent .futures .Future , ProcessNode ],
249
242
infinitive : str ,
250
243
present : str ,
251
- wait : bool = False ,
252
244
timeout : t .Optional [float ] = None ,
253
245
) -> None :
254
246
"""Process a mapping of futures representing an action on an active process.
255
247
256
248
This function will echo the correct information strings based on the outcomes of the futures and the given verb
257
249
conjugations. You can optionally wait for any pending actions to be completed before the functions returns and use a
258
- timeout to put a maximum wait time on the actions.
250
+ timeout to put a maximum wait time on the actions. TODO fix docstring
259
251
260
252
:param futures: The map of action futures and the corresponding processes.
261
253
:param infinitive: The infinitive form of the action verb.
262
254
:param present: The present tense form of the action verb.
263
- :param wait: Set to ``True`` to wait for process response, for ``False`` the action is fire-and-forget.
264
255
:param timeout: Raise a ``ProcessTimeoutException`` if the process does not respond within this amount of seconds.
265
256
"""
266
- scheduled = {}
267
-
268
- def handle_result (result ):
269
- if result is True :
270
- LOGGER .report (f'request to { infinitive } Process<{ process .pk } > sent' )
271
- elif result is False :
272
- LOGGER .error (f'problem { present } Process<{ process .pk } >' )
273
- elif isinstance (result , kiwipy .Future ):
274
- LOGGER .report (f'scheduled { infinitive } Process<{ process .pk } >' )
275
- scheduled [result ] = process
276
- else :
277
- LOGGER .error (f'got unexpected response when { present } Process<{ process .pk } >: { result } ' )
257
+ if not timeout :
258
+ return
259
+
260
+ LOGGER .report (f"waiting for process(es) { ',' .join ([str (proc .pk ) for proc in futures .values ()])} " )
278
261
279
262
try :
280
263
for future , process in futures .items ():
281
- # unwrap is need here since LoopCommunicator will also wrap a future
264
+ # we unwrap to the end
282
265
unwrapped = unwrap_kiwi_future (future )
283
266
try :
284
267
result = unwrapped .result (timeout = timeout )
285
268
except communications .TimeoutError :
286
- cancelled = unwrapped .cancel ()
269
+ cancelled = future .cancel ()
287
270
if cancelled :
288
271
LOGGER .error (f'call to { infinitive } Process<{ process .pk } > timed out and was cancelled.' )
289
272
else :
290
273
LOGGER .error (f'call to { infinitive } Process<{ process .pk } > timed out but could not be cancelled.' )
291
274
except Exception as exception :
292
275
LOGGER .error (f'failed to { infinitive } Process<{ process .pk } >: { exception } ' )
293
276
else :
294
- if isinstance (result , kiwipy .Future ):
295
- LOGGER .report (f'scheduled { infinitive } Process<{ process .pk } >' )
296
- scheduled [result ] = process
277
+ if result is True :
278
+ LOGGER .report (f'request to { infinitive } Process<{ process .pk } > sent' )
279
+ elif result is False :
280
+ LOGGER .error (f'problem { present } Process<{ process .pk } >' )
297
281
else :
298
- handle_result (result )
299
-
300
- if not wait or not scheduled :
301
- return
302
-
303
- LOGGER .report (f"waiting for process(es) { ',' .join ([str (proc .pk ) for proc in scheduled .values ()])} " )
304
-
305
- for future in concurrent .futures .as_completed (scheduled .keys (), timeout = timeout ):
306
- process = scheduled [future ]
307
-
308
- try :
309
- result = future .result ()
310
- except Exception as exception :
311
- LOGGER .error (f'failed to { infinitive } Process<{ process .pk } >: { exception } ' )
312
- else :
313
- handle_result (result )
314
-
282
+ LOGGER .error (f'got unexpected response when { present } Process<{ process .pk } >: { result } ' )
315
283
except concurrent .futures .TimeoutError :
316
284
raise ProcessTimeoutException (
317
285
f'timed out trying to { infinitive } processes { futures .values ()} \n '
0 commit comments