is_cancelled

Contents

is_cancelled#

rapidtools.core.is_cancelled(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_cancelled(), 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_cancelled
>>>
>>> stop = threading.Event()
>>> is_cancelled(None), is_cancelled(stop)
(False, False)
>>> stop.set()
>>> is_cancelled(stop)
True