【发布时间】:2012-04-28 13:56:57
【问题描述】:
我有以下比较用户输入的代码
import thread,sys
if(username.get_text() == 'xyz' and password.get_text()== '123' ):
thread.start_new_thread(run,())
def run():
print "running client"
start = datetime.now().second
while True:
try:
host ='localhost'
port = 5010
time = abs(datetime.now().second-start)
time = str(time)
print time
client = socket.socket()
client.connect((host,port))
client.send(time)
except socket.error:
pass
如果我只是调用函数 run() 它可以工作,但是当我尝试创建一个线程来运行这个函数时,由于某种原因没有创建线程并且没有执行 run() 函数我找不到任何错误..
提前谢谢...
【问题讨论】:
-
你能提供一个最小的运行示例吗?此代码不会运行,因为名称
username和password未定义。
标签: python multithreading sockets client