Python线程给出全局名称未定义错误

以下代码给出了一个未定义的全局名称错误,但据我所知,该名称已定义.我是
Python的新手,这是一个范围问题吗?

import os, socket
from threading import Thread

class serv:
    def __init__(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.bind(('', 443))

    def run(self):
        self.socket.listen(10)
        print "Listening"
        self.conn, self.addr = self.socket.accept()
        try:
            Thread(target=clientThread, args=(self.conn,)).start()
        except Exception, errtxt:
            print errtxt

    def exit(self):
        print "Disconnected"
        self.conn.close()

    def clientThread(conn):
        print "Connected"
        while 1:
            conn.send("Hello, worlds!\n")

S = serv()
S.run()

具体错误是

global name 'clientThread' is not defined 

最佳答案 你应该使用

self.clientThread
点赞