From: Constantin Date: Sun, 15 Sep 2013 12:01:11 +0000 (+0200) Subject: cleanup atexit X-Git-Url: https://git.ralfj.de/saartuer.git/commitdiff_plain/fa2004af2aafefcc66f8668c29f373fbcfdfaffb?ds=inline cleanup atexit --- diff --git a/ringd b/ringd index 812043a..3835d9c 100755 --- a/ringd +++ b/ringd @@ -1,5 +1,5 @@ #!/usr/bin/python3 -import time, socket +import time, socket, atexit import RPi.GPIO as GPIO tuerSock = "/run/tuer.sock" @@ -8,6 +8,7 @@ ringPin = 18 GPIO.setmode(GPIO.BOARD) GPIO.setup(ringPin, GPIO.IN) +atexit.register(GPIO.cleanup); lastEvent = 0 @@ -33,4 +34,4 @@ while True: if data != b'1': print("Received unexpected answer %s" % str(data)) -GPIO.cleanup() + diff --git a/tuerd b/tuerd index a283f26..1d49f65 100755 --- a/tuerd +++ b/tuerd @@ -1,5 +1,5 @@ #!/usr/bin/python3 -import time, socket, os, stat +import time, socket, os, stat, atexit from datetime import datetime import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) @@ -52,6 +52,9 @@ pinlist = [Pinoutput("open", 12, [(True, 0.3), (False, 5.0)]), # ******** main ********* +# at the end do a cleanup +atexit.register(GPIO.cleanup); + # convert list of pin objects to dictionary for command lookup pindict = {} for pin in pinlist: @@ -88,6 +91,3 @@ while True: # close connection cleanly conn.close() -# FIXME will this be executed after receiving a terminating signal? -GPIO.cleanup() -