From 5189fd3e50e82697699bcd138e2116ced10eb5df Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 14 Jul 2020 13:52:50 -0700 Subject: [PATCH] Fix threading issue that stopped Blinka from working on MicroPython --- src/busio.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/busio.py b/src/busio.py index 5456f65..279bd46 100755 --- a/src/busio.py +++ b/src/busio.py @@ -7,7 +7,10 @@ See `CircuitPython:busio` in CircuitPython for more details. * Author(s): cefn """ -import threading +try: + import threading +except ImportError: + threading = None import adafruit_platformdetect.constants.boards as ap_board import adafruit_platformdetect.constants.chips as ap_chip @@ -69,8 +72,8 @@ class I2C(Lockable): (scl, sda), i2cPorts ) ) - - self._lock = threading.RLock() + if threading is not None: + self._lock = threading.RLock() def deinit(self): """Deinitialization""" @@ -80,11 +83,13 @@ class I2C(Lockable): pass def __enter__(self): - self._lock.acquire() + if threading is not None: + self._lock.acquire() return self def __exit__(self, exc_type, exc_value, traceback): - self._lock.release() + if threading is not None: + self._lock.release() self.deinit() def scan(self): -- 2.49.0