Skip to content

Commit

Permalink
Merge pull request #370 from bitcraze/krichardsson/issue-368
Browse files Browse the repository at this point in the history
Avoid possible deadlock in param
  • Loading branch information
ataffanel authored Dec 7, 2022
2 parents a8bcbd0 + 644a5a0 commit def4331
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cflib/crazyflie/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import logging
import struct
from collections import namedtuple
from queue import Empty
from queue import Queue
from threading import Event
from threading import Lock
Expand Down Expand Up @@ -556,13 +557,17 @@ def request_extended_types(self, elements):

def _close(self):
# First empty the queue from all packets
while not self.request_queue.empty():
self.request_queue.get()
try:
while True:
self.request_queue.get(block=False)
except Empty:
pass

# Then force an unlock of the mutex if we are waiting for a packet
# we didn't get back due to a disconnect for example.
try:
self._lock.release()
except Exception:
except RuntimeError:
pass

def run(self):
Expand Down Expand Up @@ -595,13 +600,17 @@ def __init__(self, cf, useV2, updated_callback):

def close(self):
# First empty the queue from all packets
while not self.request_queue.empty():
self.request_queue.get()
try:
while True:
self.request_queue.get(block=False)
except Empty:
pass

# Then force an unlock of the mutex if we are waiting for a packet
# we didn't get back due to a disconnect for example.
try:
self.wait_lock.release()
except Exception:
except RuntimeError:
pass

def request_param_setvalue(self, pk):
Expand Down

0 comments on commit def4331

Please sign in to comment.