#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Essex, VT
    Posts
    5
    Rep Power
    0

    Auto execute program


    Is there a way that I can automatically execute a program at a certain time or something like that from inside the program.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I seem to remember something about a Python module for doing this kind of thing... ah, maybe i imagined it... can't seem to find it anywhere . Anyway you should look at the time and datetime modules:

    http://www.python.org/doc/2.3.3/lib/...-datetime.html
    http://www.python.org/doc/2.3.3/lib/module-time.html

    Is the execution time built-in to the program or do you want to have a config file? Just i might have something for you if you want to write it with a config file

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    Using Windows' scheduler or some cron daemon under Linux might be simpler, though, depending on your needs and what's available.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Essex, VT
    Posts
    5
    Rep Power
    0

    Built in


    I was thinking of having it built in but if there is any other way that I can do it then you can tell me. Thanks
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ok after a little prodding around i finally bothered to finish an idea i had a while ago... basically its a python module (attached) which defines only one class that you can use to scedual tasks from Python (like cron on *nix only interally).

    The class can load input from a file or youcan pass it in directly; should be pretty easy to use (especially since i went nuts and commented the thing to hell )

    Code:
    example input file (default time format)
    13:55:00 echo hey
    13:56:00 echo bye
    This format can be set to be more or less specific depending on you're needs

    Note: for this to work you may need to have a long running process.

    Anyway, hope this helps or at least gives you some ideas

    Mark.
    Attached Files
    programming language development: www.netytan.com Hula

  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    2
    Rep Power
    0
    cron.py doenst work so u know any other programs
  12. #7
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Cron was tested and worked fine on XP with Python 2.3.3 and was also tested by others - Great if you look at the source for this you will knowtice that you need a config file (named 'cron.txt' in cron.py) to hold the desired 'time system_command' lines.

    Just one reason why this didnt work for you.

    Unfortunatly i dont have the resources to test this right now since i'm doing a little traveling but if anyone can find a bug in it i'll try and make time to fix it ok .

    Mark.
    Last edited by netytan; April 26th, 2004 at 12:03 AM.
    programming language development: www.netytan.com Hula

  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    25
    Rep Power
    0
    I'd try using the sched module.
    http://docs.python.org/lib/module-sched.html
  16. #9
  17. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    For most cases (and in this one) particular all you need to do is use time.sleep() inside a while loop in order to preform a task every n number of seconds as i sugested in PM i.e.

    Code:
    #!/usr/bin/env python
    
    import time
    
    while True:
        ...
        do whatever here
        ...
        time.sleep(seconds)
    Hope this clears things up,

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo