taskiq-python / taskiq

Distributed task queue with full async support
MIT License
808 stars 50 forks source link

Get PID of leader worker #227

Open ice1x opened 11 months ago

ice1x commented 11 months ago

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.

s3rius commented 11 months ago

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

ice1x commented 11 months ago

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 commented 11 months ago

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)