title: Call a function every 1 seconds in python
body: <p><a href="https://i.stack.imgur.com/9EEdK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9EEdK.png" alt="enter image description here"></a>    </p>
  
  <pre><code>class Viewer:
     def __init__(self, width, height, arm_info, point_info, point_l):
       self.list_x = [1,2,3,4]
       self.list_y = [5,6,7,8]
       self.i = 0
       self.arm_info = arm_info
       self.point_info = point_info
    def on_key_press(self,symbol,modifiers):
       if symbol == pyglet.window.key.Z:
           self.point_info[:] = [self.list_x[self.i],self.list_y[self.i]]
           self.i += 1
  </code></pre>
  
  <p>Here to update the point_info[:] I have to press the 'Z' everytime, I just want Z to be pressed once to update point_info[:] in every 1 second . </p>
  
  <pre><code> def on_key_press(self,symbol,modifiers):
       if symbol == pyglet.window.key.Z:
           for i in range(0,4):
               self.point_info[:] = [self.list_x[i],self.list_y[i]]
               time.sleep(1)
  </code></pre>
  
  <p>I have tried above but it doesn't work. How can I do this?</p>
  
  <p>Here is the complete code, the render method is called from another module.</p>
  
  <pre><code>class Viewer(pyglet.window.Window):
  def __init__(self, width, height, arm_info, point_info, point_l, mouse_in):
      self.list_x = [100,150,200,300,400]
      self.list_y = [100,150,200,300,400]
  #initialisation of variables
  
  def render(self):
      pyglet.clock.tick()
      self._update_arm()
      self.switch_to()
      self.dispatch_events()
      self.dispatch_event('on_draw')
      self.flip()
  
  def on_draw(self):
  #draws on the screen
  def _update_arm(self):
  #updates the coordinates of the arm , as it moves
  
  
  def on_key_press(self, symbol, modifiers):
      #HERE LIES THE PROBLEM
      if symbol == pyglet.window.key.S:
          for j in range(0,4):
              self.point_info[:] = [self.list_x[j],self.list_y[j]]
              print(self.point_info)
              #below 2 lines are for drawing on the screen.
              self.clear()
              self.batch.draw()
  
              j=+1
              time.sleep(1)
  </code></pre>