Koed00 / django-q

A multiprocessing distributed task queue for Django
https://django-q.readthedocs.org
MIT License
1.83k stars 286 forks source link

qcluster doesn't stop with control C #494

Open vsoch opened 3 years ago

vsoch commented 3 years ago

Hi there! I'm using qcluster alongside django, and when I press control C to stop it, it never seems to quit. E.g.,

$ snakeface
22:40:14 [Q] INFO Q Cluster skylark-north-four-cardinal starting.
22:40:14 [Q] INFO Process-1:1 ready for work at 24973
22:40:14 [Q] INFO Process-1:2 ready for work at 24974
22:40:14 [Q] INFO Process-1:3 ready for work at 24975
22:40:14 [Q] INFO Process-1:4 ready for work at 24976
22:40:14 [Q] INFO Process-1:5 ready for work at 24977
22:40:14 [Q] INFO Process-1:6 ready for work at 24978
22:40:14 [Q] INFO Process-1:7 ready for work at 24979
22:40:14 [Q] INFO Process-1:8 ready for work at 24980
22:40:14 [Q] INFO Process-1:9 monitoring at 24981
22:40:14 [Q] INFO Process-1 guarding cluster skylark-north-four-cardinal
22:40:14 [Q] INFO Process-1:10 pushing tasks at 24982
22:40:14 [Q] INFO Q Cluster skylark-north-four-cardinal running.
22:40:14 [Q] INFO Q Cluster skylark-harry-bravo-michigan starting.
22:40:14 [Q] INFO Process-1:1 ready for work at 24986
22:40:14 [Q] INFO Process-1:2 ready for work at 24987
22:40:14 [Q] INFO Process-1:3 ready for work at 24988
22:40:14 [Q] INFO Process-1:4 ready for work at 24989
22:40:14 [Q] INFO Process-1:5 ready for work at 24990
22:40:14 [Q] INFO Process-1:6 ready for work at 24991
22:40:14 [Q] INFO Process-1:7 ready for work at 24992
22:40:14 [Q] INFO Process-1:8 ready for work at 24993
22:40:14 [Q] INFO Process-1:9 monitoring at 24994
22:40:14 [Q] INFO Process-1 guarding cluster skylark-harry-bravo-michigan
22:40:14 [Q] INFO Process-1:10 pushing tasks at 24995
22:40:14 [Q] INFO Q Cluster skylark-harry-bravo-michigan running.
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
December 05, 2020 - 22:40:15
Django version 3.0.8, using settings 'snakeface.settings'
Starting development server at http://127.0.0.1:5555/
Quit the server with CONTROL-C.
^C22:40:20 [Q] INFO Q Cluster skylark-north-four-cardinal stopping.
22:40:20 [Q] INFO Q Cluster skylark-harry-bravo-michigan stopping.
22:40:20 [Q] INFO Process-1 stopping cluster processes
22:40:20 [Q] INFO Process-1:10 stopped pushing tasks
22:40:20 [Q] INFO Process-1:1 stopped doing work
22:40:20 [Q] INFO Process-1:2 stopped doing work
22:40:20 [Q] INFO Process-1:3 stopped doing work
22:40:20 [Q] INFO Process-1:4 stopped doing work
22:40:20 [Q] INFO Process-1:5 stopped doing work
22:40:20 [Q] INFO Process-1:6 stopped doing work
22:40:20 [Q] INFO Process-1:7 stopped doing work
22:40:20 [Q] INFO Process-1:8 stopped doing work
22:40:20 [Q] INFO Process-1 stopping cluster processes
22:40:20 [Q] INFO Process-1:10 stopped pushing tasks
22:40:21 [Q] INFO Process-1:1 stopped doing work
22:40:21 [Q] INFO Process-1:2 stopped doing work
22:40:21 [Q] INFO Process-1:3 stopped doing work
22:40:21 [Q] INFO Process-1:4 stopped doing work
22:40:21 [Q] INFO Process-1:5 stopped doing work
22:40:21 [Q] INFO Process-1:6 stopped doing work
22:40:21 [Q] INFO Process-1:7 stopped doing work
22:40:21 [Q] INFO Process-1:8 stopped doing work
22:40:21 [Q] INFO Process-1 waiting for the monitor.
22:40:21 [Q] INFO Process-1:9 stopped monitoring results
22:40:21 [Q] INFO Q Cluster skylark-north-four-cardinal has stopped.
22:40:21 [Q] INFO Process-1 waiting for the monitor.
22:40:21 [Q] INFO Process-1:9 stopped monitoring results
22:40:21 [Q] INFO Q Cluster skylark-harry-bravo-michigan has stopped.

^C^C^C^C^C^C

The server and qcluster are run from within the client start script (the snakeface command above) which uses the management.run_command to do this:

    management.call_command("makemigrations", verbosity=args.verbosity)
    management.call_command("migrate", verbosity=args.verbosity)
    management.call_command("qcluster", verbosity=args.verbosity)
    management.call_command(
        "collectstatic", verbosity=args.verbosity, interactive=False
    )
    management.call_command(
        "runserver", args.port, verbosity=args.verbosity, noreload=not args.noreload
    )

Is there something I am missing here?

berekashvili22 commented 3 years ago

I had same issue , try CTRL + BREAK .

Moon-developer commented 3 years ago

My laptop does not have a BREAK key or shortcut. What is the alternative?

theletterjeff commented 2 years ago

I have the same issue. Is there a solution?

Chibdibs commented 2 years ago

CTRL+C and CTRL+BREAK both don't work.

brian-xp commented 2 years ago

Came across this thread since I'm having a similar issue. Has anyone found a solution to this by chance?

Pressing CTRL + C performs the stop procedure (I think) but all the workers immediately get reincarnated and it never truly stops.

LevonW-IIS commented 2 years ago

I'm having the same issue. qcluster simply reincarnates workers

oladimillion commented 2 years ago

Use CTRL + Z or Command + Z to terminate qcluster

andrew-mendes commented 1 year ago

Use CTRL + Z or Command + Z to terminate qcluster

This doesn't work for me too. Only way I found is to close the terminal. Does anybody know if that is secure tho?

Edit: When I do that and I run it again, it always returns some errors and then resumes the task normally. I suspect that might be due to leftover tasks still in memory failing to complete. Any light on this would be greatly appreciated.


  File "C:\Python\lib\site-packages\django_q\cluster.py", line 432, in worker
    res = f(*task["args"], **task["kwargs"])
TypeError: 'NoneType' object is not callable

10:15:04 [Q] ERROR Failed [seven-july-thirteen-mars] - 'NoneType' object is not callable : Traceback (most recent call last):
  File "C:\Python\lib\site-packages\django_q\cluster.py", line 432, in worker
    res = f(*task["args"], **task["kwargs"])
TypeError: 'NoneType' object is not callable

10:15:04 [Q] ERROR Failed [island-aspen-winter-artist] - 'NoneType' object is not callable : Traceback (most recent call last):
  File "C:\Python\lib\site-packages\django_q\cluster.py", line 432, in worker
    res = f(*task["args"], **task["kwargs"])
TypeError: 'NoneType' object is not callable```
JoeHitchen commented 1 year ago

After a discussion on a fork, I was able to stop qcluster with Ctrl+Break - performed by Ctrl+Fn+B - which is handled differently to the KeyboardInterrupt sent by Ctrl+C.

This list of equivalent keyboard shortcuts might be useful for others: https://en.wikipedia.org/wiki/Break_key#Keyboards_without_Break_key

some-sh commented 7 months ago

Thanks @JoeHitchen , Ctrl+Fn+B worked in Windows

AnanyaP-WDW commented 6 months ago

Use CTRL + Z or Command + Z to terminate qcluster

Thanks. This works for mac