]> Repositories - hackapet/Adafruit_Blinka.git/blobdiff - src/busio.py
Fix some pylint errors
[hackapet/Adafruit_Blinka.git] / src / busio.py
index be09cd08833c79e41a7e378bf2b02ca7578122cf..b478ec06c6a37cdef99720b71712607e1f0d0253 100755 (executable)
@@ -7,6 +7,8 @@ See `CircuitPython:busio` in CircuitPython for more details.
 * Author(s): cefn
 """
 
+import threading
+
 from adafruit_blinka import Enum, Lockable, agnostic
 from adafruit_blinka.agnostic import board_id, detector
 import adafruit_platformdetect.board as ap_board
@@ -39,6 +41,8 @@ class I2C(Lockable):
                 "No Hardware I2C on (scl,sda)={}\nValid I2C ports: {}".format((scl, sda), i2cPorts)
             )
 
+        self._lock = threading.RLock()
+
     def deinit(self):
         try:
             del self._i2c
@@ -46,9 +50,11 @@ class I2C(Lockable):
             pass
 
     def __enter__(self):
+        self._lock.acquire()
         return self
 
     def __exit__(self, exc_type, exc_value, traceback):
+        self._lock.release()
         self.deinit()
 
     def scan(self):