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?

Date 2014-12-18 09:45 -0700
From Michael Torrie <torriem@gmail.com>
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>
Newsgroups comp.lang.python
Message-ID <mailman.17034.1418921123.18130.python-list@python.org> (permalink)

Show all headers | 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