python程序运行进程、使用时间、剩余时间显示功能的实现代码

作者:泉伟 时间:2023-04-14 11:16:33 

有很多程序运行时间比较长,如果不将运行过程输出将很难判断程序运行的时间。下边这段程序将按照上图所示的格式输出程序运行进程、已用时间、剩余时间。


def time_change(time_init):  #定义将秒转换为时分秒格式的函数
 time_list = []
 if time_init/3600 > 1:
   time_h = int(time_init/3600)
   time_m = int((time_init-time_h*3600) / 60)
   time_s = int(time_init - time_h * 3600 - time_m * 60)
   time_list.append(str(time_h))
   time_list.append('h ')
   time_list.append(str(time_m))
   time_list.append('m ')
 elif time_init/60 > 1:
   time_m = int(time_init/60)
   time_s = int(time_init - time_m * 60)
   time_list.append(str(time_m))
   time_list.append('m ')
 else:
   time_s = int(time_init)
 time_list.append(str(time_s))
 time_list.append('s')
 time_str = ''.join(time_list)
 return time_str
if __name__=="__main__":
 process = .0
 start = time.time()
 for i in range(total_num):
    ···
    ···
    ···
   if process < (i*1.0/total_num):
     if process != 0:
       end = time.time()
       use_time = end-start
       all_time = use_time / process
       res_time = all_time - use_time
       str_ues_time = time_change(use_time)
       str_res_time = time_change(res_time)
       print("Percentage of progress:%.0f%%  Used time:%s  Rest time:%s "%(process*100,str_ues_time,str_res_time))
     process = process + 0.01

总结

以上所述是小编给大家介绍的python程序运行进程、使用时间、剩余时间显示功能的实现代码,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

来源:https://blog.csdn.net/qq_35451572/article/details/80379304

标签:python,程序运行,剩余时间
0
投稿

猜你喜欢

  • vue3封装侧导航文字骨架效果组件

    2024-04-27 16:10:03
  • MySQL:Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEM

    2024-01-27 16:55:14
  • SpringBoot图文并茂详解如何引入mybatis与连接Mysql数据库

    2024-01-25 15:07:32
  • 教你使用python搭建一个QQ机器人实现叫起床服务

    2021-04-22 02:25:41
  • 从p开始,循序渐进学习WEB标准

    2008-03-08 18:53:00
  • Python3.5面向对象与继承图文实例详解

    2021-05-14 15:48:42
  • PHP自动生成缩略图函数的源码示例

    2023-06-26 19:13:37
  • Python中表达式x += y和x = x+y 的区别详解

    2022-02-24 04:11:19
  • python django生成迁移文件的实例

    2023-07-01 18:48:31
  • Django实现学生管理系统

    2023-07-22 18:05:59
  • JS闭包经典实例详解

    2024-05-09 10:20:27
  • 认识Javascript数组

    2009-08-27 15:26:00
  • python 发送和接收ActiveMQ消息的实例

    2022-08-23 18:45:20
  • Excel数据导入到Access,Sql Server中示例代码

    2007-10-07 12:03:00
  • Golang实现文件夹的创建与删除的方法详解

    2024-02-02 13:57:02
  • 使用Pytorch搭建模型的步骤

    2022-03-05 21:28:38
  • 基于PyQt5制作一个windows通知管理器

    2022-10-18 19:28:24
  • 基于Python Dash库制作酷炫的可视化大屏

    2022-09-13 14:20:32
  • Pycharm学习教程(7)虚拟机VM的配置教程

    2022-10-12 16:49:33
  • mysql left join快速转inner join的过程

    2024-01-26 19:08:17
  • asp之家 网络编程 m.aspxhome.com