Alright, I found a way to make it happen by changing the _worker
function:
def _worker(self):
while True:
try:
self._dojob(self.jobqueue.get(True, 3))
except QueueEmptyError:
pass
if os.getppid() == 1:
print('Parent process died, stopping worker.')
sys.exit(0)
When the parent process dies without ending the daemon _worker
processes os.getppid()
will return 1 instead of the parents ID on UNIX-like systems. Every 3 seconds it stops waiting for new objects in the queue and checks for that.
I don't feel like this is the proper way though.