mirror of
				https://github.com/KevinMidboe/python-gpiozero.git
				synced 2025-10-29 17:50:37 +00:00 
			
		
		
		
	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:
		| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user