Prevent race condition on self._drive_thread = None

This commit is contained in:
Fabio Manganiello 2019-12-23 18:48:01 +01:00
parent 7f440a9160
commit ff9e1c71a7
1 changed files with 3 additions and 2 deletions

View File

@ -125,8 +125,9 @@ class GpioZeroborgPlugin(Plugin):
self._direction = direction.lower()
if not self._drive_thread:
self._drive_thread = threading.Thread(target=_run)
self._drive_thread.start()
drive_thread = threading.Thread(target=_run)
drive_thread.start()
self._drive_thread = drive_thread
get_bus().post(ZeroborgDriveEvent(direction=self._direction, motors=self.directions[self._direction]))
return {'status': 'running', 'direction': direction}