Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82635

Re: Is there a way to schedule my script?

References <mailman.17010.1418843457.18130.python-list@python.org> <54921444$0$12995$c3e8da3$5496439d@news.astraweb.com> <CAAp0bGv4cwqUJ2Gi1ROJB=_HhBDbeSEqOWpJX3x0CtyZkXULcQ@mail.gmail.com>
From Juan Christian <juan0christian@gmail.com>
Date 2014-12-18 12:37 +0000
Subject Re: Is there a way to schedule my script?
Newsgroups comp.lang.python
Message-ID <mailman.17030.1418906581.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Wed Dec 17 2014 at 11:04:16 PM Juan Christian <juan0christian@gmail.com>
wrote:
Thanks. That was a great answer. I'll redo my code. It's running and will
only run in my Docker container (Ubuntu Server 14.04.1) so I'll use cron.

Indeed, currently I'm using something like that:

while True:
if 9 < datetime.now().hour < 24:
# do stuff
sleep(randint(3, 6) * 60)
else:
# see you in 9 hours
sleep(9 * 60 * 60)

I knew it wasn't a good approach, but as least it was running as intended!


I read the cron doc, it's really simple to use, but one think I didn't see
out-of-the-box is a way to set a random time, like 'execute this in a 5~10
min interval', I can only set specific times like 'execute this each
minute, each hour, each 10min' and so on.

I found a 'fix' for that using $RANDOM in the crontab. Another workaround
would be to set a fixed 5min interval in cron and inside my script have a
random int (0 or 1), when 0, the script doesn't execute and 1 it execute,
so that way I'd have a little 'randomness' that I need.

Which approach would be the best?

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-17 19:10 +0000
  Re: Is there a way to schedule my script? John Gordon <gordon@panix.com> - 2014-12-17 19:41 +0000
    Re: Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-17 19:51 +0000
      Re: Is there a way to schedule my script? John Gordon <gordon@panix.com> - 2014-12-17 20:23 +0000
        Re: Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-17 20:42 +0000
        Re: Is there a way to schedule my script? Chris Angelico <rosuav@gmail.com> - 2014-12-18 08:34 +1100
        Re: Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-17 21:47 +0000
        Re: Is there a way to schedule my script? Michael Torrie <torriem@gmail.com> - 2014-12-18 09:45 -0700
  Re: Is there a way to schedule my script? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-18 10:39 +1100
    Re: Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-18 01:04 +0000
    Re: Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-18 12:37 +0000
    Re: Is there a way to schedule my script? Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-18 09:23 -0700
    Re: Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-18 22:13 +0000
    Re: Is there a way to schedule my script? Chris Angelico <rosuav@gmail.com> - 2014-12-19 12:32 +1100
    Re: Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-19 01:55 +0000
    Re: Is there a way to schedule my script? Terry Reedy <tjreedy@udel.edu> - 2014-12-19 00:58 -0500
  Re: Is there a way to schedule my script? Josh English <Joshua.R.English@gmail.com> - 2014-12-18 09:13 -0800
    Re: Is there a way to schedule my script? Juan Christian <juan0christian@gmail.com> - 2014-12-18 18:29 +0000

csiph-web