linux - How to run a python script with Raspberry Pi until we stop it manually -
currently working both raspberry pi , arduino @ moment. arduino in cases, if start running script, run until stop them manually.
i wondering if there way same raspberry pi when using python. raspberry pi, when use,
sudo python myprogramme.py
it runs code once , stopped. there way can run same code command line several times until stop them manually (for example, in matlab, have use crtl+z stop running script)? (it may possible using loop wondering if can without using loop.) hope query makes sense. point of doing send continuous information sensor system.
according comments ... when hit ctrl+c script gets keyboard interrupt , can gracefully shut down.
your code:
import smbus import time while true: try: # i2c bus bus = smbus.smbus(1) # bmp280 address, 0x76(118) # read data 0x88(136), 24 bytes b1 = bus.read_i2c_block_data(0x76, 0x88, 24) # ... , rest of code. # add short sleep here @ end... sleep(0.1) except keyboardinterrupt: # quit sys.exit()
Comments
Post a Comment