【发布时间】:2014-06-04 14:56:01
【问题描述】:
我的程序中需要这个输出:
from __future__ import print_function
import time
import threading
def timer():
for h in range(0, 24):
for m in range(0, 60):
for s in range(0, 60):
time.sleep(1)
print ("Elapsed time : %s:%s:%s" % (h, m, s), end="\r")
def insert_record():
#do insert record operation below code is sample
count = 0
for i in range(1, 100):
count += 1
time.sleep(1)
print ("Inserted records in mysql database : %s " % count, end="\r")
if __name__ == "__main__":
threading.Thread(target=insert_record()).start()
threading.Thread(target=timer()).start()
直到 insert_record function() 工作,timer() 函数在下一行显示经过的时间。 但没有在终端显示经过的时间:-( 刚刚在终端中显示了 insert_record() 输出。
我想要这个输出:
在mysql数据库中插入记录:5456672
经过时间:20:15:30
请帮助我,抱歉英语口述不好。
【问题讨论】:
-
您想在命令行循环中运行程序吗?或者你是在谈论程序中的一个循环,它应该显示每个循环的时间?你得说清楚,否则很难帮上忙。
-
你能再次看到我的代码吗?
标签: python printing timer multiprocessing output