1

What I tried but is not working:

if __name__ == "__main__":

    # Start celery worker in detached mode
    app.worker_main(argv = ['-A', 'myapp', 'worker', '-Q', 'myqueue', '-D'])

    # Other python code operations that need celery worker to run properly ...

    # Shutdown celery worker
    app.worker_main(argv = ['-A', 'myapp', 'control', 'shutdown'])

When I run this script, it executes and ends without any error, but the celery worker did not get launched and the python code after is not executed.

How to solve this ?

Rivaille
  • 11
  • 3
  • this line `app.worker_main(argv = ['-A', 'myapp', 'control', 'shutdown'])` stop all the workers that you have – WhiteAB Jun 28 '22 at 15:06
  • @WhiteAB yes after the execution of the previous code, but even if I remove this line it still the same behaviour – Rivaille Jun 28 '22 at 15:18
  • the argument for `app.worker_main(arg)` is a list check this https://stackoverflow.com/questions/23389104/how-to-start-a-celery-worker-from-a-script-module-main – WhiteAB Jun 28 '22 at 15:34
  • @WhiteAB I don't get your point, I use a list too – Rivaille Jun 28 '22 at 15:47
  • sorry, the diferrence works for v3.1.12, but also check this https://stackoverflow.com/questions/23389104/how-to-start-a-celery-worker-from-a-script-module-main#:~:text=Since%20Celery%205%20things%20have%20been%20changed – WhiteAB Jun 28 '22 at 15:50
  • If this is all you want, why not simply run a shell script? I would make the shell script run celery worker with `--pidfile=/path/to/celery1.pid` and then when you want it dead, simply send SIGTERM to the process with PID in that file. SIGTERM will initiate "warm" shutdown, while SIGQUIT will initiate "cold" shutdown. – DejanLekic Jul 01 '22 at 09:45

0 Answers0