Skip to content

Close the param threads properly if close is called. #535

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ToveRumar
Copy link
Contributor

@ToveRumar ToveRumar commented Apr 3, 2025

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.

Note that this has been failing during system tests, so this is tested there.

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
It was started on setting up the crazyflie, and if the crazflie is never closed
the thread will keep running. It makes more sense to start it when opening and
stop it when closing
@gemenerik gemenerik requested a review from Copilot April 24, 2025 08:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a thread closure issue by ensuring that a None object is sent via the queue to unblock threads waiting on queue.get() when the connection is closed and also defers parameter initialization until a link is open.

  • In cflib/crazyflie/param.py, the _close and run methods are modified to set the _should_close flag and enqueue a None to unblock the run loop.
  • In cflib/crazyflie/init.py, the Param object is now deferred (set to None) during initialization and later instantiated upon opening a link.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cflib/crazyflie/param.py Added None enqueuing and _should_close flag updates to unstick thread waits.
cflib/crazyflie/init.py Deferred Param instantiation until a link is opened.
Comments suppressed due to low confidence (1)

cflib/crazyflie/param.py:589

  • [nitpick] While using 'continue' to skip processing a None value works since the loop condition will eventually cause exit, replacing 'continue' with a 'break' may simplify the logic for immediately terminating the thread once closure is signaled.
if pk is None:  # Put none to close the thread

@@ -119,7 +119,7 @@ def __init__(self, link=None, ro_cache=None, rw_cache=None):
self.extpos = Extpos(self)
self.log = Log(self)
self.console = Console(self)
self.param = Param(self)
self.param = None
Copy link
Preview

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting self.param to None in the initializer may lead to potential null reference errors if other parts of the code access param before open_link is called. Consider adding a guard or clearly documenting this initialization sequence.

Suggested change
self.param = None
self.param = Param(self)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant