docstr: Clear jobs and stop the workflow.
  
  If Snakemake is configured to restart jobs then the job might have
  "restart_times" left and we just decrement and let the scheduler
  try to run the job again.
docstr_tok: ["Clear","jobs","and","stop","the","workflow",".","If","Snakemake","is","configured","to","restart","jobs","then","the","job","might","have","''","restart_times","''","left","and","we","just","decrement","and","let","the","scheduler","try","to","run","the","job","again","."]
code: def _handle_error(self, job, postprocess_job: bool = True):
      """Clear jobs and stop the workflow.
  
      If Snakemake is configured to restart jobs then the job might have
      "restart_times" left and we just decrement and let the scheduler
      try to run the job again.
      """
      # must be called from within lock
      if postprocess_job and not self.workflow.dryrun:
          async_run(
              job.postprocess(
                  error=True,
              )
          )
      self.get_executor(job).handle_job_error(job)
      self.running.remove(job)
      self._free_resources(job)
      # attempt starts counting from 1, but the first attempt is not
      # a restart, hence we subtract 1.
      if job.restart_times > job.attempt - 1:
          logger.info(
              f"Trying to restart job {self.workflow.dag.jobid(job)}."
          )
          job.attempt += 1
          # add job to those being ready again
          self.workflow.dag._ready_jobs.add(job)
      else:
          self._errors = True
          self.failed.add(job)
  
imports: import asyncio
  from collections import defaultdict
  import math
  import os, signal, sys
  import threading
  from functools import partial
  from itertools import chain, accumulate
  from contextlib import ContextDecorator
  from snakemake_interface_executor_plugins.scheduler import JobSchedulerExecutorInterface
  from snakemake_interface_executor_plugins.registry import ExecutorPluginRegistry
  from snakemake_interface_executor_plugins.registry import Plugin
  from snakemake_interface_executor_plugins.settings import ExecMode
  from snakemake.common import async_run
  from snakemake.exceptions import RuleException, WorkflowError, print_exception
  from snakemake.logging import logger
  from fractions import Fraction
label_desc: Use image node_id 15 for calling the JobScheduler obj's underlying member method code with example usage: obj._handle_error(job, postprocess_job) without return types