taskiq icon indicating copy to clipboard operation
taskiq copied to clipboard

Get PID of leader worker

Open ice1x opened this issue 2 years ago • 3 comments
trafficstars

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.

ice1x avatar Oct 18 '23 10:10 ice1x

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

s3rius avatar Oct 18 '23 11:10 s3rius

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

ice1x avatar Oct 18 '23 11:10 ice1x

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)

ice1x avatar Oct 18 '23 16:10 ice1x