Skip to content

Commit d582c8c

Browse files
committed
Close the param threads properly if close is called.
Put a None object on the queue if closed and read this out. The lock was released but since the queue was emptied the run task would never return from queue.get() and then this thread could not be closed. Make sure to unblock it by sending None and then setting should_close variable
1 parent cf0bd19 commit d582c8c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cflib/crazyflie/param.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ def _close(self):
576576

577577
# Then force an unlock of the mutex if we are waiting for a packet
578578
# we didn't get back due to a disconnect for example.
579+
self._should_close = True
580+
self.request_queue.put(None)
579581
try:
580582
self._lock.release()
581583
except RuntimeError:
@@ -584,6 +586,8 @@ def _close(self):
584586
def run(self):
585587
while not self._should_close:
586588
pk = self.request_queue.get() # Wait for request update
589+
if pk is None: # Put none to close the thread
590+
continue
587591
self._lock.acquire()
588592
if self._cf.link:
589593
self._req_param = struct.unpack('<H', pk.data[1:3])[0]
@@ -616,9 +620,11 @@ def close(self):
616620
self.request_queue.get(block=False)
617621
except Empty:
618622
pass
619-
623+
self._should_close = True
624+
self.request_queue.put(None)
620625
# Then force an unlock of the mutex if we are waiting for a packet
621626
# we didn't get back due to a disconnect for example.
627+
622628
try:
623629
self.wait_lock.release()
624630
except RuntimeError:
@@ -677,6 +683,8 @@ def request_param_update(self, var_id):
677683
def run(self):
678684
while not self._should_close:
679685
pk = self.request_queue.get() # Wait for request update
686+
if pk is None: # Put none to close the thread
687+
continue
680688
self.wait_lock.acquire()
681689
if self.cf.link:
682690
if self._useV2:

0 commit comments

Comments
 (0)