Being more robust against multiple concurrent plugin initializations with a lock

This commit is contained in:
Fabio Manganiello 2018-08-21 09:10:57 +02:00
parent 09d7d98ae3
commit e5d67c9393

View file

@ -26,6 +26,7 @@ class GpioZeroborgPlugin(Plugin):
_drive_thread = None
_can_run = False
_direction = None
_init_in_progress = threading.Lock()
def __init__(self, directions = {}, *args, **kwargs):
@ -83,7 +84,12 @@ class GpioZeroborgPlugin(Plugin):
self.directions = directions
self.auto_mode = False
self._direction = None
self.zb = None
if self._init_in_progress.locked():
raise RuntimeError("ZeroBorg initialization already in progress")
with self._init_in_progress:
self.zb = ZeroBorg.ZeroBorg()
self.zb.Init()
self.zb.SetCommsFailsafe(True)