From aa3aa21695441b23d8986907422b29f9d9eef263 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 16 Jun 2017 22:12:16 +0100 Subject: [PATCH] Reference Device directly Don't go via the instance dict (prevents anyone overriding the reservations dict or pin_factory at the instance level) --- gpiozero/devices.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gpiozero/devices.py b/gpiozero/devices.py index 9b587b3..ed8d37c 100644 --- a/gpiozero/devices.py +++ b/gpiozero/devices.py @@ -224,7 +224,7 @@ class Device(ValuesMixin, GPIOBase): p.address if isinstance(p, Pin) else p for p in pins_or_addresses ) - with self._res_lock: + with Device._res_lock: for address in addresses: for device_ref in Device._reservations[address]: device = device_ref() @@ -247,10 +247,10 @@ class Device(ValuesMixin, GPIOBase): p.address if isinstance(p, Pin) else p for p in pins_or_addresses ) - with self._res_lock: + with Device._res_lock: for address in addresses: Device._reservations[address] = [ - ref for ref in self._reservations[address] + ref for ref in Device._reservations[address] if ref() not in (self, None) # may as well clean up dead refs ] @@ -259,13 +259,13 @@ class Device(ValuesMixin, GPIOBase): Releases all pin reservations taken out by this device. See :meth:`_release_pins` for further information). """ - with self._res_lock: + with Device._res_lock: Device._reservations = defaultdict(list, { address: [ ref for ref in conflictors if ref() not in (self, None) ] - for address, conflictors in self._reservations.items() + for address, conflictors in Device._reservations.items() }) def _conflicts_with(self, other): @@ -424,8 +424,8 @@ class GPIODevice(Device): self._reserve_pins(pin) else: # Check you can reserve *before* constructing the pin - self._reserve_pins(self._pin_factory.pin_address(pin)) - pin = self._pin_factory.pin(pin) + self._reserve_pins(Device._pin_factory.pin_address(pin)) + pin = Device._pin_factory.pin(pin) self._pin = pin self._active_state = True self._inactive_state = False