Skip to content

Instantly share code, notes, and snippets.

@vaclavcadek
Created May 23, 2017 14:16
Show Gist options
  • Save vaclavcadek/b432a33fa049683241a12ec549f4ed78 to your computer and use it in GitHub Desktop.
Save vaclavcadek/b432a33fa049683241a12ec549f4ed78 to your computer and use it in GitHub Desktop.
Periodic write to file every second.
import sched, time
from datetime import datetime
s = sched.scheduler(time.time, time.sleep)
def read_signal(sc):
with open('/home/vasek/Downloads/test.csv', 'a') as log:
log.write('{timestamp},{temperature}\n'.format(timestamp=datetime.now(), temperature=23.0))
# do your stuff
s.enter(1, 1, read_signal, (sc,))
s.enter(1, 1, read_signal, (s,))
s.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment