Terminating a async background job

There is a timeout you can set for which the async engine will
automatically kill the job if it runs longer than that. There is,
however, no way to stop an async job on demand. Once started, they
presently complete.

It would require the following changes to support on demand slaying:

(A) In the file that is to be polled by async_status and is set up by
async_wrapper, record the pid of the innermost forked kid (presumably
as a simple "pid" variable in the JSON file)

(B) Teach async_status a "terminate=yes|no" option that kills the pid
set in the job status file from (A). If pid was in the JSON file it
would kill the process, otherwise, it would return an error that the
pid was not
yet recorded. If the status of the job was not marked as running it
would not try to kill anything.

Patches, provided they stay concise, would be accepted, and probably
are not that difficult to add.

(Given that terminating a module midstream is not something we
generally want to encourage, this should not be wired up to
/usr/bin/ansible or /usr/bin/ansible-playbook as an Interrupt Handler,
as tempting as that might be -- once a playbook launches a module, I
want it to complete)

In my particular scenario, I cannot provide a timeout and wait for it to be exceeded, instead I would like to kill the job on demand. I understand that terminating a job midstream is not to be encouraged, but in certain scenarios this functionality is desirable. Suppose I am running a backup job using ansible on a remote host, there might be some conditions where I would like to be able to kill the job, for example because of disk space issues.

Your suggested changes is what I was thinking of doing as well, and I think I can come up with the patch. Thank you for your reply.