cleanup atexit
authorConstantin <constantin@exxxtremesys.lu>
Sun, 15 Sep 2013 12:01:11 +0000 (14:01 +0200)
committerConstantin <constantin@exxxtremesys.lu>
Sun, 15 Sep 2013 12:01:11 +0000 (14:01 +0200)
ringd
tuerd

diff --git a/ringd b/ringd
index 812043adb4ea914ca15a21c9c8ed70a7dc21ec28..3835d9c80e868e0f0b743d46faafc50a4d7fb31d 100755 (executable)
--- 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 a283f26d9221c47feae5b31758b7dc0181cb84ca..1d49f652b5e7b892a7ec0789c96a308f39d9cf6a 100755 (executable)
--- 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()
-