kraiz / django-crontab

dead simple crontab powered job scheduling for django.
Other
842 stars 112 forks source link

UNIX process doesn't exit after crontab command finishes #79

Open socialglass opened 6 years ago

socialglass commented 6 years ago

Environment & Versions

All the django-crontab commands that run and spawn a UNIX process, none of the process seems to be exiting after the command is done. They just lie around doing nothing but taking up memory. This includes add, run, show & remove commands.

I tried a small hack in the run command, where in the class Commands (crontab.py), I put this piece of code in the handle() method -

        elif options['subcommand'] == 'run':
            Crontab().run_job(options['jobhash'])
            os.kill(os.getpid(), signal.SIGTERM)

But this doesn't seem to make any difference.

Any ideas?

kraiz commented 6 years ago

Do you have thos problem with other management commands? Does it relate to #37?

socialglass commented 6 years ago

Yes now this problem is with all management commands - show, run, add, remove. As for #37, the issue was only for the run command, which I got around at that time by doing the os.kill() as I mentioned above. It doesn't work anymore.

socialglass commented 6 years ago

Any ideas?

kraiz commented 6 years ago

Does the runtime reach you os.kill? I never saw this behavior. Can you debug it, print some traces? I'm unable to reproduce it.

makelove commented 6 years ago

Same problems

CentOS Linux release 7.4.1708 Django==2.0.5 django-crontab==0.7.1

while run django-crontab command: add show it will not auto exit I have to PRESS : CTRL+C

^CException ignored in: <module 'threading' from '/usr/lib64/python3.6/threading.py'>
Traceback (most recent call last):
  File "/usr/lib64/python3.6/threading.py", line 1294, in _shutdown
    t.join()
  File "/usr/lib64/python3.6/threading.py", line 1056, in join
    self._wait_for_tstate_lock()
  File "/usr/lib64/python3.6/threading.py", line 1072, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt

when I running crontab manually, also have to KeyboardInterrupt

and When it run in background, it remain runing

ps aux|grep django-cronjobs
prod     16351  0.0  0.0 113128  1204 ?        Ss   10:30   0:00 /bin/sh -c /home/prod/.py36/bin/python /home/prod/work/www/wwwdp/manage.py crontab run 8088ab3df8b20e2220fd2fb2b84a631d > /home/prod/jd_orders_out.log # django-cronjobs for wwwdp
prod     16582  0.0  0.0 113128  1204 ?        Ss   10:40   0:00 /bin/sh -c /home/prod/.py36/bin/python /home/prod/work/www/wwwdp/manage.py crontab run 8088ab3df8b20e2220fd2fb2b84a631d > /home/prod/jd_orders_out.log # django-cronjobs for wwwdp
prod     16957  0.0  0.0 113128  1204 ?        Ss   10:50   0:00 /bin/sh -c /home/prod/.py36/bin/python /home/prod/work/www/wwwdp/manage.py crontab run 8088ab3df8b20e2220fd2fb2b84a631d > /home/prod/jd_orders_out.log # django-cronjobs for wwwdp
prod     17157  0.0  0.0 113128  1204 ?        Ss   11:00   0:00 /bin/sh -c /home/prod/.py36/bin/python3 /home/prod/work/www/wwwdp/manage.py crontab run 8088ab3df8b20e2220fd2fb2b84a631d > /home/prod/jd_orders_out.log # django-cronjobs for wwwdp

How to fix this problem ?

makelove commented 6 years ago

this problem cause my server run out memory, can not ssh ,have to force to reboot ☹️

Rakk4403 commented 2 years ago

@makelove I've got a same problem, and find a way.

# settings.py
CRONTAB_COMMAND_PREFIX = '/bin/bash -c "'
CRONTAB_COMMAND_SUFFIX = '"'

this will wrap your python execute command with double quote.

I don't know why exactly but works well on my ubuntu 20.04 server. (It was not shown on my MacBook, another Ubuntu 20.04. weird) I just guess /bin/sh -c processed only next word, not whole command.

Rakk4403 commented 2 years ago

No it was not. Not working now 😢

@makelove I've got a same problem, and find a way.

# settings.py
CRONTAB_COMMAND_PREFIX = '/bin/bash -c "'
CRONTAB_COMMAND_SUFFIX = '"'

this will wrap your python execute command with double quote.

I don't know why exactly but works well on my ubuntu 20.04 server. (It was not shown on my MacBook, another Ubuntu 20.04. weird) I just guess /bin/sh -c processed only next word, not whole command.