is_canceled

Contents

is_canceled#

rapidtools.core.is_canceled(cancel_event: Event | None) → bool[source]#

Return True if cancel_event exists and has been set.

This is the non-raising counterpart of raise_if_canceled(), useful in loops that want to exit gracefully and keep partial results.

Parameters:

cancel_event (Event | None) – The event to inspect. None means cancellation is not enabled.

Returns:

bool – True only when an event was supplied and it is set.

Example

>>> import threading
>>> from rapidtools.core import is_canceled
>>>
>>> stop = threading.Event()
>>> is_canceled(None), is_canceled(stop)
(False, False)
>>> stop.set()
>>> is_canceled(stop)
True