Being more robust against multiple concurrent plugin initializations with a lock
This commit is contained in:
parent
09d7d98ae3
commit
e5d67c9393
1 changed files with 10 additions and 4 deletions
|
@ -26,6 +26,7 @@ class GpioZeroborgPlugin(Plugin):
|
||||||
_drive_thread = None
|
_drive_thread = None
|
||||||
_can_run = False
|
_can_run = False
|
||||||
_direction = None
|
_direction = None
|
||||||
|
_init_in_progress = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, directions = {}, *args, **kwargs):
|
def __init__(self, directions = {}, *args, **kwargs):
|
||||||
|
@ -83,11 +84,16 @@ class GpioZeroborgPlugin(Plugin):
|
||||||
self.directions = directions
|
self.directions = directions
|
||||||
self.auto_mode = False
|
self.auto_mode = False
|
||||||
self._direction = None
|
self._direction = None
|
||||||
|
self.zb = None
|
||||||
|
|
||||||
self.zb = ZeroBorg.ZeroBorg()
|
if self._init_in_progress.locked():
|
||||||
self.zb.Init()
|
raise RuntimeError("ZeroBorg initialization already in progress")
|
||||||
self.zb.SetCommsFailsafe(True)
|
|
||||||
self.zb.ResetEpo()
|
with self._init_in_progress:
|
||||||
|
self.zb = ZeroBorg.ZeroBorg()
|
||||||
|
self.zb.Init()
|
||||||
|
self.zb.SetCommsFailsafe(True)
|
||||||
|
self.zb.ResetEpo()
|
||||||
|
|
||||||
|
|
||||||
def _get_measurement(self, plugin, timeout):
|
def _get_measurement(self, plugin, timeout):
|
||||||
|
|
Loading…
Reference in a new issue