-
Notifications
You must be signed in to change notification settings - Fork 943
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
Remove pointless try/except in polling_task #2091
Conversation
If the asyncio.ensure_future(self.poll_task) # noqa: RUF006 |
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.
Your idea is not bad, but it seems you broke something so that the reconnect does not run.
The cancelled most likely comes from the same code, as you write, but it might also come from transport (I think),
If we can avoid the try/cancel I am all in favour, I just cannot see how the pyserial object is being closed if the task is cancelled. |
hmmm the failing test in 3.10 is a tcp test, I am confused |
Is there any way that |
I am not sure if asyncio.protocol cancels running tasks in some cases, apart from that I think you are correct that it is only self.close() that does it. |
I've noticed we have a rare flaky test again, but have not investigated further. |
I will keep an eye open, I have had seen it lately. |
See #2090. This PR goes a step further.
This code is a stack of clever hacks.
pymodbus/pymodbus/transport/serialtransport.py
Lines 45 to 48 in d6704a2
The purpose of this code is to cancel
self.poll_task()
and then set it toNone
afterwards.Because the code is sync,
await
cannot be used to ensure the cancellation.Hack #1 - use
ensure_future
Then
ruff
complains withRUF006
. This could have been safely ignored - nobody cares if the GC cleans up, since it's immediately set toNone
. Instead...Hack #2 - use
self.future
to hold a reference.Next
mypy
complains thatself.future
is untyped.Hack #3 - add an annotation to the constructor.
Looking at
polling_task
, I see no purpose to catchingasyncio.CancelledTask
. All it does is callself.close()
.... which is the very code that cancelled it!I think the whole
try/Except
and stack of hacks can be removed. :)