1

If I execute a Python 3 script inside my Raspberry Pi 3 and it uses time.sleep(wait), it only works interactively. If I background the process using &, the script doesn't seem to work at all and I don't see any output in my CSV file the script writes to. It stays at file size 0 forever.

I've tried this by running a script directly (read-sensor >/var/lib/envirophat/sensor.csv &) and the same inside a Docker container (I'm using HypriotOS).

How can I read the sensor faster than once per minute (using crontab) but not continuously without any kind of sleep?

Jon Brisbin
  • 1,299
  • 8
  • 11
  • I doubt it's time.sleep that is the problem. You might have a buffering issue? https://stackoverflow.com/questions/107705/disable-output-buffering – Matt Feb 15 '17 at 02:55

1 Answers1

1

Looks like the output buffering was in fact the issue. It was working but never outputting anything so I couldn't tell. Using python3 -u seems to do the trick. I updated my Docker image to reflect this.

Jon Brisbin
  • 1,299
  • 8
  • 11