以下代碼給出了全局名稱未定義的錯誤,但據我所知,名稱是定義的。我是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
'pi'是一個概念loooooong在Raspberry Pi來到現場之前;請僅爲數學常量使用'pi'標籤。 :-) – 2013-03-06 21:02:27
會這樣,謝謝。 – 2013-03-06 21:04:45