循环,计时器和python中的线程

时间:2018-06-07 03:08:12

标签: python python-2.7 anaconda spyder

如何检查此脚本将每2分钟运行一次,文件'odata_peng5.txt'每2分钟仍可更新一次?

import pandas as pd
import threading

def printit():
      threading.Timer(120.0, printit).start()
      df = pd.read_csv('data_peng5.txt', header=None)

      a=100
      b=1/a

      df[15] = df[3]+b+50

      df.to_csv('odata_peng5.txt', header=None, index=False)

      print "Hello, World!"
printit()

输出:

=============== RESTART: C:/Users/xxx/timer3.py ===============
>>> 

尽管如此,我正在使用模式打印模式进行测试:

#import pandas as pd
import threading

def printit():
  threading.Timer(120.0, printit).start()
  print "Hello, World!"

printit()

输出:

=============== RESTART: C:/Users/xxx/timer3.py ===============
Hello, World!
>>> Hello, World!
Hello, World!

2 个答案:

答案 0 :(得分:0)

  $scope.gateway = {
    port1 : 0,
    port2:  0,
    port3 : 0,
    port4: 0
  };
  $scope.mask = 0

这将每120秒重复一次printit功能

答案 1 :(得分:0)

较新的代码

import pandas as pd
import threading

def printit():
      threading.Timer(60.0, printit).start()
      df = pd.read_csv('data_peng5.txt', header=None)

      a=100
      b=1/a

      df[15] = df[3]+b+50

      df.to_csv('odata_peng5.txt', header=None, index=False)

      #YourCode Sir
      f=open('odata_peng5.txt','r')
      message = f.read()
      print massage
      f.close()

      print "Hello, World!"

printit()