之前引用局部变量我有一段代码,这里在Python线程(服务器),但是当我运行客户端发现这些错误:“UnboundLocalError:局部变量‘一站式’分配之前引用” :的Python:UnboundLocalError:分配
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)
一个重复的哦,所以许多[其他](https://www.google.com/search?q=stackoverflow+UnboundLocalError%3A+local+variable+referenced+before+assignment)... – shx2 2013-03-18 12:05:05
可能重复的[UnboundLocalError:局部变量...在赋值之前引用](http://stackoverflow.com/questions/4048745/unboundlocalerror-local-variable-referenced-before-assignment) – 2013-03-18 15:27:48