我正在用python3制作一个简单的客户机/服务器程序,在客户机中我想要一个时钟或运行时间的打印输出。我试图使它在一个循环中,从程序的开始,但在一个线程中,所以其余的代码继续进行。你知道吗
class time_thread():
def run(self):
loop = 0
while (zetime > -1):
print(zetime);
zetime = zetime + 1;
time_thread.start()
zetime = 0
这是我目前所拥有的,但它不起作用。上面写着:
time_thread has no attribute start()
我是新手,以前没用过线程,所以我不知道该怎么做。有更好的办法吗?你知道吗
首先,要使用Thread模块,必须在类上继承类Thread,这样就可以使用像start这样的方法。 要计算时间,可以使用datetime。你知道吗
把这个放好
假设你定义了一个函数,比如:
然后在程序中:
你应该做你想做的工作。你知道吗
注意:我使用了Python2.7,所以它可能与3.x略有不同
我想这就是你想要的:
相关问题 更多 >
编程相关推荐