ここにPythonスレッド(サーバー)のコードがありますが、クライアントを実行すると、次のエラーが見つかりました:「UnboundLocalError:ローカル変数'stop'が割り当て前に参照されました」:
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)