码迷,mamicode.com
首页 > 编程语言 > 详细

python 超过一定时间,自动重新运行函数

时间:2020-12-10 11:00:26      阅读:3      评论:0      收藏:0      [点我收藏+]

标签:ogr   pre   转义   class   超过   port   简约   str   main   

代码:

 1 # -*- coding:utf-8 -*-
 2 import re
 3 # import Util.NEO4J.neo4j_util as Neo
 4 import sys
 5 import os
 6 import time
 7 sentence=""
 8 num_zhang=[]
 9 
10 
11 def restart_program():
12   python = sys.executable
13   os.execl(python, python, * sys.argv)
14 
15 def Get():
16 
17     for i in range(200000):
18         print(i)
19 
20 
21 if __name__ =="__main__":
22     # cmd=‘python D:\\b.py‘# 必须转义‘\‘
23     # os.system(cmd)
24     time_start = time.time()
25     Get()
26     time_end = time.time()
27     time_sub= time_end - time_start
28     i=0
29     print("NJNNNNNNNNNNNNNNNNNNNNNNNN")
30     if(time_sub>1):
31         str = "CHCP 65001" + "&&"
32         str += "E:" + "&&"
33         str += r"cd E:\pycharm\WorkPlace\Graduation_project\Util" + "&&"
34         str += "python test.py "
35         # print(str)
36         print("TIME______",i,"________",time_sub)
37         i=i+1
38         cmd = os.system(str)
39         # print(cmd)

 ———————————————————————————————————————————————————————

更新:

简约版:

 1 def restart(time_start,time_end,sub_deadline):
 2     time_sub = time_end - time_start
 3     i = 0
 4     print("NJNNNNNNNNNNNNNNNNNNNNNNNN")
 5     if (time_sub > sub_deadline):
 6         str = "CHCP 65001" + "&&"
 7         str += "E:" + "&&"
 8         str += r"cd E:\pycharm\WorkPlace\Graduation_project\Util" + "&&"
 9         str += "python test.py "
10         # print(str)
11         print("TIME______", i, "________", time_sub)
12         i = i + 1
13         cmd = os.system(str)
14         # print(cmd)

 

python 超过一定时间,自动重新运行函数

标签:ogr   pre   转义   class   超过   port   简约   str   main   

原文地址:https://www.cnblogs.com/smartisn/p/14091918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!