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


Groups > comp.lang.python > #82640

Re: Is there a way to schedule my script?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; '"if': 0.09; 'solution,': 0.09; 'subject:script': 0.09; 'runs': 0.10; 'api': 0.11; 'python': 0.11; 'windows': 0.15; 'callable': 0.16; 'command-line': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'imports': 0.16; "module's": 0.16; 'wrote:': 0.18; 'module': 0.19; 'file,': 0.19; 'things.': 0.19; 'header:User-Agent:1': 0.23; 'script.': 0.24; '(or': 0.24; 'sort': 0.25; 'script': 0.25; 'nearly': 0.26; 'this:': 0.26; 'skip:_ 20': 0.27; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'testing': 0.29; 'ideal': 0.29; 'dec': 0.30; 'code': 0.31; '(although': 0.31; 'coded': 0.31; 'easy,': 0.31; 'fine,': 0.31; 'file': 0.32; 'this.': 0.32; 'probably': 0.32; 'run': 0.32; 'another': 0.32; 'linux': 0.33; 'running': 0.33; 'entirely': 0.33; 'mac': 0.33; 'problem': 0.35; 'add': 0.35; 'interface,': 0.36; 'module.': 0.36; 'done': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'similar': 0.36; 'changing': 0.37; 'so,': 0.37; 'christian': 0.38; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'even': 0.60; 'solve': 0.60; 'john': 0.61; 'simply': 0.61; 'first': 0.61; 'complete': 0.62; 'real': 0.63; 'such': 0.63; 'fashion': 0.64; 'within': 0.65; 'subject:there': 0.68; 'manner': 0.72
X-Virus-Scanned amavisd-new at torriefamily.org
Date Thu, 18 Dec 2014 09:45:15 -0700
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11
MIME-Version 1.0
To python-list@python.org
Subject Re: Is there a way to schedule my script?
References <mailman.17010.1418843457.18130.python-list@python.org> <m6sm9d$5es$1@reader1.panix.com> <mailman.17012.1418845926.18130.python-list@python.org> <m6soo5$mc3$1@reader1.panix.com> <CAAp0bGubrVZAYgXp3yZfWty+2fJGR7-=qn0jkquV9DCGqx4VGg@mail.gmail.com>
In-Reply-To <CAAp0bGubrVZAYgXp3yZfWty+2fJGR7-=qn0jkquV9DCGqx4VGg@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17034.1418921123.18130.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418921123 news.xs4all.nl 2943 [2001:888:2000:d::a6]:52988
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 5012
X-Received-Body-CRC 1673925560
Xref csiph.com comp.lang.python:82640

Show key headers only | View raw


On 12/17/2014 01:42 PM, Juan Christian wrote:
> On Wed Dec 17 2014 at 6:25:39 PM John Gordon <gordon@panix.com> wrote:
> If you want to solve your problem entirely within Python, look at the
> "scheduler" module. (Although even this isn't a complete solution, as you
> still have to make sure the program is running in the first place...)
> 
> 
> My script is running fine, Win/OSX/Linux and I don't want to ruin that
> using system specific things.

Wrong.  You don't have to change or ruin your script.  If your script is
done right, you put all the real work inside of callable functions
anyway, and probably have some sort of "main" function that gets called
in a manner similar to this:

if __name__=="__main__":
    my_main()

If so, then you create platform-dependent code in another file that
simply imports your existing, working script as a module and runs that
main function.  On Windows you write a service API wrapper.  On Linux
you can run the script directly from cron.  On Mac you can just bundle a
launchd control file (or use cron).

If your script is not coded in such a fashion as to make turning it into
an importable module easy, I highly recommend changing your to work in
this way.  Once my python programs get halfway useful I always try to
reorganize my code in such a way that it can be used as a module.
Because invariable I find that I do want to add another layer, and the
modules are ideal for this.  Nearly every script has the "if
__name__=='__main__'" block at the end of the file, where it provides
standalone features such as a command-line interface, or provides
testing of the module's features.

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