Add close method and context manager

Permit devices to be explicitly closed and used as context managers.
Also deal with cleanup properly at script end and ensure objects don't
step on the global cleanup function.
This commit is contained in:
Dave Jones
2015-09-29 18:51:44 +01:00
parent 8fc8e3444e
commit 034b88b478
3 changed files with 109 additions and 39 deletions

View File

@@ -1,11 +1,6 @@
from __future__ import absolute_import
import atexit
from RPi import GPIO
from .devices import (
_gpio_threads_shutdown,
GPIODeviceError,
GPIODevice,
)
@@ -35,11 +30,3 @@ from .boards import (
TrafficHat,
)
def gpiozero_shutdown():
_gpio_threads_shutdown()
GPIO.cleanup()
atexit.register(gpiozero_shutdown)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)