mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-23 02:08:12 +08:00
According to multiprocessing documentation for Value (https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Value) reads and writes are protected with lock when the lock argument is True (the default) or the lock argument is an instance of Lock or RLock. The documentation states that operations like += are not atomic as that involves reading and writing. On the worker side the critical section includes also storing finished task result because the timeout could happen after the task function has finished but before the result has been stored and timer.value has been updated to tell the guard process that the task has been finished. On the guard side the critical section includes all checks done to see if the worker has timed out or died and the actual reincarnation function because the worker could update timer value to -1 (idle) or -2 (recycle) after the guard has seen timer value 0 (timeout) and is going to terminate the worker.