Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid possible deadlock in param #370

Merged
merged 2 commits into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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