Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!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.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'else:': 0.03; 'indeed,': 0.09; 'subject:script': 0.09; 'random': 0.14; '(ubuntu': 0.16; '1),': 0.16; 'execute,': 0.16; 'redo': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'true:': 0.16; 'wrote:': 0.18; 'code.': 0.18; '<': 0.19; 'thanks.': 0.20; 'email addr:gmail.com>': 0.22; 'script': 0.25; 'least': 0.26; 'to:2**1': 0.27; 'fixed': 0.29; "doesn't": 0.30; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'container': 0.31; 'workaround': 0.31; 'stuff': 0.32; 'run': 0.32; 'another': 0.32; 'running': 0.33; "i'd": 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; "didn't": 0.36; "i'll": 0.36; 'subject:?': 0.36; 'christian': 0.38; 'server': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'simple': 0.61; 'times': 0.62; 'great': 0.65; 'hours': 0.66; 'answer.': 0.68; '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:references:from:date:message-id:subject:to :content-type; bh=ObQ+jKwNaqzkdtht1BJnQ01RLnL6j/MibJabdCutSvA=; b=fJEsIuTbun8Sj7zuGzWzm1PMCsSH6OaexhDv80Oog/69kU7g0jZ5977XAYrq+9WKdZ wLnbrjfMhRf3fe8kymPxKe/KH9XgfUxs78LHYHJtHh1W0QD+yJETewrli835Ael8mOmu B23eS00FOk6pe0VrZLjxDH79HwW0PtALa0nQlJchwXRT1uTZx4QZnMv8bLSPeHOgE7cY MiDOs0Lf7waTaQu2ee8qkK3xEMtX0kQpfdJ+QTEezsn2gW2+O1+tIc8U/DvXFeWkTVzt Y/Bbr4qcyP6eapPGNy9MRmQ3IC6VsUBYowICaMUjjB3Iwf+AliHpxv+KkYTCdGjj1Rkw wUIw== X-Received: by 10.50.82.66 with SMTP id g2mr13151477igy.19.1418906271515; Thu, 18 Dec 2014 04:37:51 -0800 (PST) MIME-Version: 1.0 References: <54921444$0$12995$c3e8da3$5496439d@news.astraweb.com> From: Juan Christian Date: Thu, 18 Dec 2014 12:37:50 +0000 Subject: Re: Is there a way to schedule my script? To: "Steven D'Aprano" , python-list@python.org Content-Type: multipart/alternative; boundary=089e0111b848488d99050a7cdcd3 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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418906581 news.xs4all.nl 2876 [2001:888:2000:d::a6]:52867 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 6208 X-Received-Body-CRC: 740098976 Xref: csiph.com comp.lang.python:82635 --089e0111b848488d99050a7cdcd3 Content-Type: text/plain; charset=UTF-8 On Wed Dec 17 2014 at 11:04:16 PM Juan Christian 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? --089e0111b848488d99050a7cdcd3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable --089e0111b848488d99050a7cdcd3--