title: Python: UnboundLocalError: local variable referenced before assignment
body: <p>I've got a piece of code here in Python Thread (Server) but when I run the client these error was found: "UnboundLocalError: local variable 'stop' referenced before assignment":</p>
  
  <pre><code>import threading
  import msvcrt
  
  stop = False
  Buffer= 1024
  
  class ChatServer(threading.Thread):
     def __init__(self,channel,addr,counter):
         self.channel = channel
         self.addr = addr
         self.counter = counter
         threading.Thread.__init__(self)
         self.start()
  
     def run(self):
         # press s to trigger
         if msvcrt.kbhit():
             if msvcrt.getch() == 's':
                 stop = True
                 print "Login is closed closed.\n"
         while 1:
             if (stop == False):
                 print "\nClient connection received!\n"
                 self.channel.send("Status: Server connection received")
  
  counter = 0                   
  server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  server.bind(("",500))
  server.listen(20)
  
  while True:
      print "\nServer awaiting connections....\n"
      channel, addr = server.accept()
      counter += 1
      ChatServer(channel,addr,counter)
  </code></pre>