-
Notifications
You must be signed in to change notification settings - Fork 76
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
Close order revert #394
Close order revert #394
Conversation
Also calls |
I decided to push my next small touch to this PR: it prevents sending commands out of order, when commands are sent in bulk. |
@@ -347,9 +347,11 @@ async def close(self): | |||
|
|||
tasks = [self._task_shutdown_entities, self._task_reconnect, self._task_connect] | |||
pending_tasks = [task for task in tasks if task and task.cancel()] | |||
pending_tasks += [self.abort_connect()] | |||
pending_tasks += [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does affect parent devices, why not move sub_devices close block above tasks cancel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary goal of the previous PR was to shutdown the whole LocalTuya fully and efficiently.
The primary goal of this PR is to fix the problem: calling abort_connect()
before closing the sub-devices causes
full featured disconnected()
of sub-devices, including launching their _task_reconnect
tasks, which is a waste of CPU time.
Now back to your question:
Doing close of sub-device before stopping those 3 tasks allows the 3 tasks to continue running during await
s for sub-devices close()
calls. This way the 3 tasks do redundant jobs, which is inefficient.
What may slightly improve the preformance is to put the sub-devices close loop between cancelling the 3 tasks and asyncio.gather
call for them. But it's a subtle improvement. Also, the current order has more predictable result.
Comment to the last commit: Idents don't really matter here, because task switch may happen at |
Comment to the last commit: The cancellation was broken by adding handlers of Note exactly 5 seconds delay between closing mains powered and then battery powered WiFi devices:
No a need to check for |
It is essential first to close the sub-devices, to make their
_is_closing==True
, and only then disconnect the gateway. There was my comment that you've removed. Now I revert your change and put back the comment.