title: UnboundLocalError when trying to use a variable in a different thread
body: <p>I'm a newbie in Python, and I need to create a matrix in one thread and in a second thread calculate main diagonal as a sum of elements which are in one row and column </p>
  
  <p><b>matrix.py</b></p>
  
  <pre><code>class MyThread(Thread):
  
      def __init__(self, number, logger):
          Thread.__init__(self)
          self.number = number
          self.logger = logger
  
      def run(self) :
          if self.number == 0:
              logger.debug('Calling martix()')
              mat = matrix()
          else:
              logger.debug('Calling recalculate()')
              recalculate(mat)
  
  def matrix():
      delimetr = "|"
      print('Enter the size of matrix \n')
      n = int(input())
      print('start at:', ctime())
      mat = [[randint(0,100) for j in range(n)] for i in range(n)]
      print('Before')  
      for i in mat:
          print(delimetr,*i,delimetr)
      return mat
  
  def get_logger():
       logger = logging.getLogger("threading_matrix")
       logger.setLevel(logging.DEBUG)
       fh = logging.FileHandler("threading_matix.log")
       fmt = '%(asctime)s - %(threadName)s - %(levelname)s - %(message)s'
       formatter = logging.Formatter(fmt)
       fh.setFormatter(formatter)
       logger.addHandler(fh)
       return logger
  
  def recalculate(mat):
      delimetr = "|"
      m=0
      score = 0;
      n = len(mat)
      for v in mat:
          score = 0;
          for i in range(n):
              score = mat[m][i] + score
          for b in range(n):
              if b == m : continue
              else:
                  score = mat[b][m] + score
          mat[m][m] = score
          m+=1
  
      print('After')    
      for i in mat:
          print(delimetr,*i,delimetr)
      print('end at:',ctime())
  
  if __name__ == '__main__':
   logger = get_logger()
   for i in range(2):
       name = "Thread #%s" % (i+1)
       thread = MyThread(i, logger)
       thread.setName(name)
       thread.start()
       thread.join()
  </code></pre>
  
  <p>When I run this I got exception</p>
  
  <pre><code>in run recalculate(mat) UnboundLocalError: local variable 'mat' referenced before assignment
  </code></pre>
  
  <p>I tried to set <code>mat</code> as a global variable but it doesn't help.</p>