How to pragmatically check for a GPIO warning? - Raspberry Pi Forums


so have python script works great @ blinking led. if run second instance of script following expected warning:
runtimewarning: channel in use, continuing anyway. use gpio.setwarnings(false) disable warnings.

have situation call program more once sometimes, never want more 1 instance run. want catch error in python code , exit instance of program, because means have instance running.

if there no way catch particular gpio runtime warning, current idiomatic way force python run 1 instance of script @ time?

help!

i don't know python, ways of checking there 1 instance of script running include:

1) create pidfile (usually in /run or /var/run same place) called scriptname.pid containing pid of script. when script starts should check presence of such file, read pid , see if pid still executing. if so, exit.

2) create lockfile. open file writing, in tmpfs (like /run again), call scriptname.lock. don't need write though. when script starts should try opening file write access, if fails file in use , copy of script running.

3) use "pidof" command check if same name running.

4) parse output "ps" command see if same name running.

there other ways too.


raspberrypi



Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support