taskiq-python/taskiq

Get PID of leader worker

ice1x opened this issue · 3 comments

Minor feature request

In Celery possible to get Master worker PID by option --pidfile=/tmp/my_file_with_pid
would be perfect to get leader worker pid in Taskiq as well.

Since we only have one master process that maintains children processes. You can get the id of it by calling os.getppid.

Since we only have one master process that maintains children processes. You can get the id of it by calling os.getppid.

I have tried to do that whily running 3 workers and i have discovered that only 2 pids stored and both from child process. I guess i should be able to get parent pid by echo $! > ./my_file while starting a broker in bash

But this workaround works only with manual launch taskiq.
In case of Docker CMD or k8s - attempt to catch PID via '& echo $! > ./my_file' leads to container/pod crash

Resolved this issue by getting PID from the beginning of taskiq worker
bash -c 'echo $$ > /tmp/my.pid; taskiq worker ###'

But this appears not useful because i am not able to add Linux signal catch to Taskiq app (because of all my code runs only in child processes, i have discovered it while printed os.getpid from the app)