********************************** Cancel Job And All Its Child Tasks ********************************** Problem ======= You want to cancel a job. Solution ======== There are two ways to cancel tasks on a job. **Method 1:** Set the :py:attr:`cancel_on_task_failure ` property to :py:obj:`True` to cancel a job's tasks automatically if one of the tasks fails. Use this option if the result of a job depends on all its child tasks completing successfully. .. literalinclude:: ..\..\..\code\HowTos\CancelJobUsingCancelOnTaskFailure.py :language: python :linenos: :lines: 1-4,4,5-10,4,11-20,4,21-22,4,23-24,4,25-26,4,27-28,4,29-30 :emphasize-lines: 25 **Method 2:** The other option is to explicitly cancel the job using the :py:meth:`cancel() ` method. .. note:: By default, the client will not wait until the task is fully canceled. To wait for the job to complete, use the overload to :py:meth:`cancel() ` and pass :py:obj:`True` to the :py:attr:`listen_for_cancellation_event` parameter. .. literalinclude:: ..\..\..\code\HowTos\CancelJobExplicitly.py :language: python :linenos: :lines: 1-2,3-15,10,16-17,10,18,10,19-20,10,21-23 :emphasize-lines: 25 Discussion ========== Within a task, check the :py:attr:`is_cancelling` flag. If is_cancelling is :py:obj:`True`, try to exit out of the task as soon as possible. Each task is given 30 seconds to gracefully finish before the process is terminated. This value can be configured by setting :py:obj:`GRACEFUL_CANCELLATION_TIMEOUT `. See Also ======== Reference """"""""" * :py:meth:`cancel() ` * :py:attr:`cancel_on_task_failure `