diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/JobAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/JobAgent.py index d88fe0ef78a..80dbd4c3f66 100755 --- a/src/DIRAC/WorkloadManagementSystem/Agent/JobAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/JobAgent.py @@ -694,7 +694,10 @@ def _checkSubmittedJobs(self): submissionErrors = [] payloadErrors = [] originalJobID = self.jobReport.jobID - for jobID, taskID in self.submissionDict.items(): + # Loop over the jobIDs submitted to the CE + # Here we iterate over a copy of the keys because we are modifying the dictionary within the loop + for jobID in list(self.submissionDict.keys()): + taskID = self.submissionDict[jobID] if taskID not in self.computingElement.taskResults: continue @@ -731,7 +734,9 @@ def _checkSubmittedJobs(self): self.log.info(message) # Remove taskID from computingElement.taskResults as it has been treated + # Remove jobID from submissionDict as it has been treated del self.computingElement.taskResults[taskID] + del self.submissionDict[jobID] self.jobReport.setJob(originalJobID) return S_OK((submissionErrors, payloadErrors)) diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py index 0495fb495de..2a53908c3a4 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py @@ -517,6 +517,7 @@ def test_submitAndCheckJob(mocker, localCE, job, expectedResult1, expectedResult jobAgent.log = gLogger.getSubLogger("JobAgent") jobAgent._initializeComputingElement(localCE) jobAgent.jobReport = JobReport(jobID) + jobAgent.jobSubmissionDelay = 3 # Submit a job result = jobAgent._submitJob( @@ -547,10 +548,6 @@ def test_submitAndCheckJob(mocker, localCE, job, expectedResult1, expectedResult assert result["OK"] assert result["Value"] == expectedResult1 - # Check that the job is still present in jobAgent.submissionDict - assert len(jobAgent.submissionDict) == 1 - assert jobID in jobAgent.submissionDict - # If the submission is synchronous jobAgent.computingElement.taskResults # should not contain the result anymore: already processed by checkSubmittedJobs if not jobAgent.computingElement.ceParameters.get("AsyncSubmission", False): @@ -576,7 +573,6 @@ def test_submitAndCheckJob(mocker, localCE, job, expectedResult1, expectedResult assert result["Value"] == expectedResult2 # From here, taskResults should be empty - assert jobID in jobAgent.submissionDict assert len(jobAgent.computingElement.taskResults) == 0