Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.089 X-Spam-Evidence: '*H*': 0.82; '*S*': 0.00; 'latter': 0.09; 'subject:script': 0.09; 'random': 0.14; '1),': 0.16; 'execute,': 0.16; 'for?': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'email addr:gmail.com>': 0.22; 'script': 0.25; '>': 0.26; 'header :In-Reply-To:1': 0.27; 'fixed': 0.29; 'am,': 0.29; "doesn't": 0.30; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'workaround': 0.31; 'another': 0.32; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; "didn't": 0.36; 'subject:?': 0.36; 'easily': 0.37; 'christian': 0.38; 'to:addr :python-list': 0.38; 'little': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'simple': 0.61; 'times': 0.62; 'kind': 0.63; 'between': 0.67; 'subject:there': 0.68; 'hour,': 0.84; 'min': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=6QwzPBlA31X8Y7yXE8bb+4B/vyLaYFZIKMAXQyoqtsw=; b=xhR8Fwjfph7LMcOPvkBkYn319dAZWUJydrAKV2AKPZnnbgY5KWa5HAf+hEstBrW5sa v2tvcYG3AxUtjdngMIxp7Uuc3GQI0MwGzIolfGA4s0qObqWdiK7/sq1T+x+hsUdJK5oZ 7H102GozDkrACOl/kLNh/qkE2KxOQO8SSWmzIVaET+RhK2kNl6GqkPDIZUB3M5XO5lqN /uQoSb8ke7wp8sumXvMB+OCXAt4jyTpDTADMCE6bz8tmzZb00VTituFKgC8hJ4M5+Sj3 9dGqfv8RhXNkfvcPfZvusVLVhVpeAUMDN8oIK2eumqhTy9YA+TgkeABHXHTrYSKh9a0+ NVxg== X-Received: by 10.66.180.109 with SMTP id dn13mr4737820pac.89.1418919826922; Thu, 18 Dec 2014 08:23:46 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <54921444$0$12995$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Thu, 18 Dec 2014 09:23:06 -0700 Subject: Re: Is there a way to schedule my script? To: Python Content-Type: multipart/alternative; boundary=047d7bf166ba3fa355050a80042a X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418919835 news.xs4all.nl 2870 [2001:888:2000:d::a6]:43166 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82637 --047d7bf166ba3fa355050a80042a Content-Type: text/plain; charset=UTF-8 On Thu, Dec 18, 2014 at 5:37 AM, Juan Christian wrote: > 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? What kind of random distribution of the time between executions are you looking for? A random sleep lends itself easily to a uniform distribution. The latter approach that you describe would result in a geometric distribution. --047d7bf166ba3fa355050a80042a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thu, Dec 18, 2014 at 5:37 AM, Juan Christian <juan0christian@gmail.com> wrot= e:
> I read the cron doc, it's really simple to use, but one thin= k 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 lik= e 'execute this each minute, each hour, each 10min' and so on.
&= gt;
> 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 execu= te and 1 it execute, so that way I'd have a little 'randomness'= that I need.
>
> Which approach would be the best?

What kind of random distribution of the time between executions are you lo= oking for? A random sleep lends itself easily to a uniform distribution. Th= e latter approach that you describe would result in a geometric distributio= n.
--047d7bf166ba3fa355050a80042a--