I had issue canceling jobs until I tried LLM's fix, which points to a potential mismatch in the source code, see below
The cancel method in ProcessExecutor fails to cancel running jobs because of a type mismatch in the pids_for_job dict lookup.
In job_wrapper, the PID is stored using job.id (a string):
pids_for_job[job.id] = os.getpid()
But in cancel, the lookup uses ref.identifier (always a UUID):
pid = self.pids_for_job.get(ref.identifier)
Since Reference.__init__ always converts to UUID:
def __init__(self, identifier: str | UUID):
if isinstance(identifier, UUID):
self.identifier = identifier
else:
self.identifier = UUID(identifier)
The lookup fails because '03ee1a46-...' (string key) != UUID('03ee1a46-...') (UUID lookup).
Fix:
pid = self.pids_for_job.get(str(ref.identifier))
Debug output confirming the issue:
cancel called with ref.identifier=03ee1a46-9253-bb07-b15d-7ba2503352c2, type=<class 'uuid.UUID'>
pids_for_job keys: ['03ee1a46-9253-bb07-b15d-7ba2503352c2']
looked up pid: None
I had issue canceling jobs until I tried LLM's fix, which points to a potential mismatch in the source code, see below
The
cancelmethod inProcessExecutorfails to cancel running jobs because of a type mismatch in thepids_for_jobdict lookup.In
job_wrapper, the PID is stored usingjob.id(a string):But in
cancel, the lookup usesref.identifier(always a UUID):Since
Reference.__init__always converts to UUID:The lookup fails because
'03ee1a46-...'(string key) !=UUID('03ee1a46-...')(UUID lookup).Fix:
Debug output confirming the issue: