code: def checkForDeadlocks(self):
          
          totalRunningJobs = len(self.batchSystem.getRunningBatchJobIDs())
          totalServicesIssued = self.serviceJobsIssued + self.preemptableServiceJobsIssued
          # If there are no updated jobs and at least some jobs running
          if totalServicesIssued >= totalRunningJobs and totalRunningJobs > 0:
              serviceJobs = [x for x in list(self.jobBatchSystemIDToIssuedJob.keys()) if isinstance(self.jobBatchSystemIDToIssuedJob[x], ServiceJobNode)]
              runningServiceJobs = set([x for x in serviceJobs if self.serviceManager.isRunning(self.jobBatchSystemIDToIssuedJob[x])])
              assert len(runningServiceJobs) <= totalRunningJobs
  
              # If all the running jobs are active services then we have a potential deadlock
              if len(runningServiceJobs) == totalRunningJobs:
                  # We wait self.config.deadlockWait seconds before declaring the system deadlocked
                  if self.potentialDeadlockedJobs != runningServiceJobs:
                      self.potentialDeadlockedJobs = runningServiceJobs
                      self.potentialDeadlockTime = time.time()
                  elif time.time() - self.potentialDeadlockTime >= self.config.deadlockWait:
                      raise DeadlockException("The system is service deadlocked - all %d running jobs are active services" % totalRunningJobs)
              else:
                  # We have observed non-service jobs running, so reset the potential deadlock
                  self.potentialDeadlockedJobs = set()
                  self.potentialDeadlockTime = 0
          else:
              # We have observed non-service jobs running, so reset the potential deadlock
              self.potentialDeadlockedJobs = set()
              self.potentialDeadlockTime = 0
docs: Checks if the system is deadlocked running service jobs.