Why ServerStop takes 10 seconds? #1719
-
I know why, it has 10 seconds sleep in it, but why does it have 10 seconds sleep? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Because that is a synchronous call, and the asynchronous part needs to time be scheduled and close down. Especially on windows this takes forever. Use async if you want something faster. |
Beta Was this translation helpful? Give feedback.
-
Might be you do not get it, but just because StartTcpServer calls asyncio.run does not mean you can do it multiple times (as you tried), that is simply not how asyncio works, please read up on asyncio before posting. Don't use startServer is you don't like it, that is a convenience function on top of the class. You can simply instantiate the ModbusTcpServer class, and manage it as you like, with the delays you want. Or make a pull request with a better solution, something that actually tests when the asyncio loop is actually closed. Have you tried all the python version on all the platforms we support, when you claim it takes less than a second. We have and we actually do every time we run CI, so there is a reason for the delay. |
Beta Was this translation helpful? Give feedback.
-
You called asyncio.run to use ServerAsyncStop, that is not how asyncio works. Pymodbus have been around for many years with many users, one of our benefits is the flexibility if you e.g. don’t like startServer, then you do not need to use it, use the server class instead. Since we stopped supporting python 3.5 and until today, pymodbus have had major changes just like python, so please accept that some things work differently than you are used to, for a lot of reasons. |
Beta Was this translation helpful? Give feedback.
-
Well ServerAsyncStop and StartAscyncTcpServer works as well, just see our examples. And as I have now said multiple times, if you do not like ServerStop, copy the function and make your own, do not expect us to do that. |
Beta Was this translation helpful? Give feedback.
Because that is a synchronous call, and the asynchronous part needs to time be scheduled and close down. Especially on windows this takes forever.
Use async if you want something faster.