@@ -231,17 +231,19 @@ async def exit(
231
231
event_listeners_timeout : timedelta | None = EVENT_LISTENERS_TIMEOUT ,
232
232
status_message : str | None = None ,
233
233
cleanup_timeout : timedelta = timedelta (seconds = 30 ),
234
+ sys_exit : Callable = sys .exit ,
234
235
) -> None :
235
236
"""Exit the Actor instance.
236
237
237
238
This stops the Actor instance. It cancels all the intervals for regularly sending `PERSIST_STATE` events,
238
239
sends a final `PERSIST_STATE` event, waits for all the event listeners to finish, and stops the event manager.
239
240
240
241
Args:
241
- exit_code: The exit code with which the Actor should fail (defaults to `0`).
242
+ exit_code: The exit code with which the program should end (defaults to `0`).
242
243
event_listeners_timeout: How long should the Actor wait for Actor event listeners to finish before exiting.
243
244
status_message: The final status message that the Actor should display.
244
245
cleanup_timeout: How long we should wait for event listeners.
246
+ sys_exit: A function to use to terminate the program (defaults to `sys.exit`)
245
247
"""
246
248
self ._raise_if_not_initialized ()
247
249
@@ -281,15 +283,17 @@ async def fail(
281
283
exit_code : int = 1 ,
282
284
exception : BaseException | None = None ,
283
285
status_message : str | None = None ,
286
+ sys_exit : Callable = sys .exit ,
284
287
) -> None :
285
288
"""Fail the Actor instance.
286
289
287
290
This performs all the same steps as Actor.exit(), but it additionally sets the exit code to `1` (by default).
288
291
289
292
Args:
290
- exit_code: The exit code with which the Actor should fail (defaults to `1`).
293
+ exit_code: The exit code with which the program should fail (defaults to `1`).
291
294
exception: The exception with which the Actor failed.
292
295
status_message: The final status message that the Actor should display.
296
+ sys_exit: A function to use to terminate the program (defaults to `sys.exit`)
293
297
"""
294
298
self ._raise_if_not_initialized ()
295
299
@@ -298,7 +302,7 @@ async def fail(
298
302
if exception and not is_running_in_ipython ():
299
303
self .log .exception ('Actor failed with an exception' , exc_info = exception )
300
304
301
- await self .exit (exit_code = exit_code , status_message = status_message )
305
+ await self .exit (exit_code = exit_code , status_message = status_message , sys_exit = sys_exit )
302
306
303
307
def new_client (
304
308
self ,
0 commit comments