django-background-tasks icon indicating copy to clipboard operation
django-background-tasks copied to clipboard

Remove the associated process when a task is deleted

Open onurmatik opened this issue 6 years ago • 3 comments

If a task is deleted before the process associated with it finishes, i.e. canceled by the user, kill that process.

This can be done by overriding the delete() method of the Task model.

onurmatik avatar May 03 '18 06:05 onurmatik

@onurmatik I'm interested - how would this be coded?

benzkji avatar Apr 07 '21 12:04 benzkji

I don't see how this should work.

It's just a python method running within a thread.

There is no thread sync and no process to kill gracefully.

Implement smaller atomic methods and chain them.

Let an atomic task of your big program trigger the next small task just before finishing.

save_user -> update_index -> blah_1 -> blah_2

philippeowagner avatar Apr 07 '21 16:04 philippeowagner

I have tasks taking a long time, and much resources. It's about planning many emails to be sent somewhen in the future, and it cannot be "atomized"...so when a planning task is not yet finished, but should aborted and restarted (let's say more emails, or, none anymore...), it could be really helpful to not wait before planning can start again from the beginning.

I can see processes that are spawned, when using async mode, so killing the process that started a task would be a solution? a bit drastic though. I dont know anything about threads and multiprocessing in python, so...maybe I'm completely wrong :-)

benzkji avatar Apr 08 '21 09:04 benzkji