title: define global variables in a function and pass on to a class
body: <p>Can any one help please,
  I am trying to sample data every x minute from the class PROCESS defined in the code below (which runs whenever called on by other functions not shown here)
  to schedule this, I am running a scheduler function every X minute, started by the MAIN function and executed by function minmax_job.</p>
  
  <p>however my function minmax_job doesn't seem to know the initial value of i 
  I have tried on and on about putting global variables and so on, but it still doesn't know that i = 0 (initially)</p>
  
  <pre><code>i = 0
  atc,otc,tssc = 0,0,0
  atf,otf,tssf = False,False,False
  
  
  class Process(threading.Thread):
      def __init__(self, buffer3, broadcast_server):
          threading.Thread.__init__(self)
          self.setDaemon(True)
          self.buffer3 = buffer3
          self.factory = broadcast_server
  
      def run(self):
          today = datetime.now()
          global time_of_last_run
          global atv1,atv2,atv3,otv1,otv2,otv3,tssv1,tssv2,tssv3
          global atf,otf,tssf
          global atc,otc,tssc
  
  
          if self.buffer3.startswith('kitchen aquarium: temp:'):
              self.temp = self.buffer3.replace('kitchen aquarium: temp:','')
              self.factory.broadcast("Aquarium temperature %s" % self.temp)
  
              if atc == 1 and atf:
                  atv1 = float(self.temp)
                  atf = False
              elif atc == 2 and atf:
                  atv2 = float(self.temp)
                  atf = False 
              elif atc == 3 and atf:
                  atv3 = float(self.temp)
                  atf = False
  
  
  def minmax_job():
  
      global atv1,atv2,atv3,otv1,otv2,otv3,tssv1,tssv2,tssv3
      global atf,otf,tssf
      global atc,otc,tssc,i
  
      if i == 3:
          i = 0
          atc = 0
  
      if i &lt; 4:
          atc = atc + 1 
          atf = True
          i = i + 1
  
  
  if __name__ == '__main__':
  
      minmax_scheduler = Scheduler()
      minmax_scheduler.add_interval_job(minmax_job, seconds=10)
      minmax_scheduler.start()
  </code></pre>