why my python code sometimes write out sensor readings twice at each crontab tilmestep -
i wrote simple python code write sensor readings csv file. set execute code every 30 mins in crontab.
the code "sometimes" write out readings twice. wrong in code? please me.
here output in cvs file:
2015-04-29 06:00:10,-0.06418023 2015-04-29 06:00:11,-0.06418023 2015-04-29 06:05:10,-0.06419048 2015-04-29 06:05:10,-0.06419048 2015-04-29 06:10:11,-0.06423425 2015-04-29 06:15:10,-0.06420538 2015-04-29 06:20:10,-0.06421749 2015-04-29 06:20:10,-0.06421749 2015-04-29 06:25:11,-0.06422214 2015-04-29 06:30:10,-0.06426219 2015-04-29 06:30:11,-0.06422587
here code:
outfile = open("chamber1.csv", "a") def bridgedata(e): global outfile ch1_1 = ch1.getvalue(0) sleep(2) outfile.write(str(datetime.strftime(datetime.now(), '%y-%m-%d %h:%m:%s')) + "," + str(ch1_lc1) + "\n") sleep(2) sys.exit()
here crontab under root directory
*/5 * * * * /root/get_sensor_output.py
simple way close outfile after write.
Comments
Post a Comment