python显示运行时间表_python:在sh上显示运行时间

最简单的方法是计算函数中需要几分钟才能完成的运行时间,然后简单地将该时间打印到shell中。然而,根据您的功能,这可能不是最好的解决方案。在

第二种方法是使用多线程。所以让这个函数在一个线程中运行一段时间,而你的程序则处于一个循环中,每隔一段时间打印出运行的时间,并寻找线程的完成。在

比如:import threading

import time

arg1=0

arg2=1

etc=2

# your function that takes a while.

# Note: If your function returns something or if you want to pass variables in/out,

# you have to use Queues

def yourFunction(arg1,arg2,etc):

time.sleep(10) #your code would replace this

# Setup the thread

processthread=threading.Thread(target=yourFunction,args=(arg1,arg1,etc)) #set the target function and any arguments to pass

processthread.daemon=True

processthread.start() # start the thread

#loop to check thread and display elapsed time

while processthread.isAlive():

print time.clock()

time.sleep(1) # you probably want to only print every so often (i.e. every second)

print 'Done'

然后,你可以通过重写shell中的时间来获得更好的效果,或者使用gui来显示进度条!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值