do something every n seconds

Discussion in 'Python' started by Santiago Caracol, Nov 25, 2010.

  1. Hello,

    how can I do something (e.g. check if new files are in the working
    directory) every n seconds in Python?

    Santiago
     
    Santiago Caracol, Nov 25, 2010
    #1
    1. Advertising

  2. > how can I do something (e.g. check if new files are in the working
    > directory) every n seconds in Python?


    The simplest method is executing time.sleep(n) within an infinite while
    loop. There are more elegant solutions: using coroutine frameworks,
    threaded task schedulers, etc.

    — Alice.
     
    Alice Bevan–McGregor, Nov 25, 2010
    #2
    1. Advertising

  3. Santiago Caracol

    Paul Rubin Guest

    Santiago Caracol <> writes:
    > how can I do something (e.g. check if new files are in the working
    > directory) every n seconds in Python?


    Don't do it that way if you can help it. Use inotify or the equivalent
    instead.
     
    Paul Rubin, Nov 25, 2010
    #3
  4. Windows or UNIX ?

    Am Do, 25.11.2010, 13:38 schrieb Santiago Caracol:
    > Hello,
    >
    > how can I do something (e.g. check if new files are in the working
    > directory) every n seconds in Python?
    >
    > Santiago
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >



    --
    MfG,

    Stefan Sonnenberg-Carstens

    IT Architect
     
    Stefan Sonnenberg-Carstens, Nov 25, 2010
    #4
  5. On Thu, 2010-11-25 at 04:38 -0800, Santiago Caracol wrote:
    > how can I do something (e.g. check if new files are in the working
    > directory) every n seconds in Python?


    Use the Python Advanced Scheduler in your application - it is a great
    little module. Then you've solved every 'scheduler' issue your
    application will ever have.
    <http://packages.python.org/APScheduler/>
    --
    Adam Tauno Williams <> LPIC-1, Novell CLA
    <http://www.whitemiceconsulting.com>
    OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba
     
    Adam Tauno Williams, Nov 25, 2010
    #5
  6. Santiago Caracol

    Steve Holden Guest

    On 11/25/2010 6:38 AM, Santiago Caracol wrote:
    > Hello,
    >
    > how can I do something (e.g. check if new files are in the working
    > directory) every n seconds in Python?
    >

    Look at the sched library, which was written to take care of
    requirements like this. Use time.sleep() as your delay function and
    time.time() as your time function.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
    See Python Video! http://python.mirocommunity.org/
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Nov 25, 2010
    #6
  7. Santiago Caracol

    km Guest

    while True:
    time.sleep(10)
    print('hello python!')

    HTH,
    KM
    On Thu, Nov 25, 2010 at 8:35 PM, Steve Holden <> wrote:
    > On 11/25/2010 6:38 AM, Santiago Caracol wrote
    >> Hello,
    >>
    >> how can I do something (e.g. check if new files are in the working
    >> directory) every n seconds in Python?
    >>

    > Look at the sched library, which was written to take care of
    > requirements like this. Use time.sleep() as your delay function and
    > time.time() as your time function.
    >
    > regards
    >  Steve
    > --
    > Steve Holden           +1 571 484 6266   +1 800 494 3119
    > PyCon 2011 Atlanta March 9-17       http://us.pycon.org/
    > See Python Video!       http://python.mirocommunity.org/
    > Holden Web LLC                 http://www.holdenweb.com/
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
     
    km, Nov 25, 2010
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    7
    Views:
    17,264
    tshad
    Mar 11, 2005
  2. 00_CP_D12
    Replies:
    3
    Views:
    9,054
    dilipv
    Feb 22, 2008
  3. Stu
    Replies:
    7
    Views:
    1,825
    Dave Thompson
    Mar 7, 2005
  4. Michael Tan
    Replies:
    32
    Views:
    1,074
    Ara.T.Howard
    Jul 21, 2005
  5. `p
    Replies:
    7
    Views:
    409
    Steve Litt
    Dec 14, 2005
Loading...

Share This Page