How to create a timer/scheduler in Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dann

    How to create a timer/scheduler in Python?

    I need what I'd call (in .Net) a timer, ie I need to run a function eg
    every 2 seconds - it doesn't need to be millisec accurate but it would
    be nice if it wasn't eg every 4 seconds or something.

    Rather surprisingly, Core Python (Chun) doesn't seem to index 'timer'
    or 'scheduler', which leaves me wondering whether this is an aspect of
    Python that isn't perhaps widely used?

    Looking around on the net I can see references to a thread timer, but
    I'm not really looking to start any new threads (I just want part of
    the GUI to update every 2 secs) and don't want to get into that sort
    of complication while still just learning Python.

    Is there really no simple timer/scheduler function available in
    Python?
  • Uwe Schmitt

    #2
    Re: How to create a timer/scheduler in Python?

    On 12 Jul., 11:30, John Dann <n...@prodata.c o.ukwrote:
    I need what I'd call (in .Net) a timer, ie I need to run a function eg
    every 2 seconds - it doesn't need to be millisec accurate but it would
    be nice if it wasn't eg every 4 seconds or something.
    >
    Rather surprisingly, Core Python (Chun) doesn't seem to index 'timer'
    or 'scheduler', which leaves me wondering whether this is an aspect of
    Python that isn't perhaps widely used?
    >
    Looking around on the net I can see references to a thread timer, but
    I'm not really looking to start any new threads (I just want part of
    the GUI to update every 2 secs) and don't want to get into that sort
    of complication while still just learning Python.
    >
    Is there really no simple timer/scheduler function available in
    Python?
    The usual way is to use threads. Depending on you GUI lib there may
    exist
    replacements for threads, eg wxPython. As most (all ?) GUIs have some
    event handling
    mechanisms they should be able to schedule tasks and process them in
    the
    background.

    By the way: Using threads in Python is quite simple, even if you are
    a novice.

    Greetings, Uwe

    Comment

    • Marc 'BlackJack' Rintsch

      #3
      Re: How to create a timer/scheduler in Python?

      On Sat, 12 Jul 2008 10:30:00 +0100, John Dann wrote:
      Looking around on the net I can see references to a thread timer, but
      I'm not really looking to start any new threads (I just want part of
      the GUI to update every 2 secs) and don't want to get into that sort
      of complication while still just learning Python.
      Look into the GUI toolkit because that's typically something solved with
      functions from the specific toolkit.
      Is there really no simple timer/scheduler function available in
      Python?
      You can do that quite easily with threads but almost all GUI toolkits
      don't like it if you access the GUI from multiple threads.

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      • Daniel Fetchinson

        #4
        Re: How to create a timer/scheduler in Python?

        I need what I'd call (in .Net) a timer, ie I need to run a function eg
        every 2 seconds - it doesn't need to be millisec accurate but it would
        be nice if it wasn't eg every 4 seconds or something.
        >
        Rather surprisingly, Core Python (Chun) doesn't seem to index 'timer'
        or 'scheduler', which leaves me wondering whether this is an aspect of
        Python that isn't perhaps widely used?
        >
        Looking around on the net I can see references to a thread timer, but
        I'm not really looking to start any new threads (I just want part of
        the GUI to update every 2 secs) and don't want to get into that sort
        of complication while still just learning Python.
        >
        Is there really no simple timer/scheduler function available in
        Python?

        You might want to look at scheduler.py from turbogears which is
        exactly the tool you describe and luckily is 99.99% independent of
        turbogears. I'd think you need to modify 1-2 lines:



        Cheers,
        Daniel
        --
        Psss, psss, put it down! - http://www.cafepress.com/putitdown

        Comment

        • MrJean1

          #5
          Re: How to create a timer/scheduler in Python?

          There is a module called sched in the standard Python library

          <http://docs.python.org/lib/module-sched.html>

          /Jean Brouwers



          John Dann wrote:
          I need what I'd call (in .Net) a timer, ie I need to run a function eg
          every 2 seconds - it doesn't need to be millisec accurate but it would
          be nice if it wasn't eg every 4 seconds or something.
          >
          Rather surprisingly, Core Python (Chun) doesn't seem to index 'timer'
          or 'scheduler', which leaves me wondering whether this is an aspect of
          Python that isn't perhaps widely used?
          >
          Looking around on the net I can see references to a thread timer, but
          I'm not really looking to start any new threads (I just want part of
          the GUI to update every 2 secs) and don't want to get into that sort
          of complication while still just learning Python.
          >
          Is there really no simple timer/scheduler function available in
          Python?

          Comment

          Working...