Closed janiversen closed 7 months ago
Use idea from @alexrudd2
future = asyncio.run_coroutine_threadsafe(cls.async_stop(), cls.active_server.loop)
future.result(timeout=10 if os.name == 'nt' else 0.1)
These are the remaining uses in production code:
[x] polling => OK https://github.com/pymodbus-dev/pymodbus/blob/504af274d920fae5e859edc7d914ce5c03a15a75/pymodbus/transport/serialtransport.py#L149
[x] reconnect delay => OK https://github.com/pymodbus-dev/pymodbus/blob/504af274d920fae5e859edc7d914ce5c03a15a75/pymodbus/transport/transport.py#L465
[x] http server shutdown => Likely OK. See conversation in https://github.com/pymodbus-dev/pymodbus/pull/2097. https://github.com/pymodbus-dev/pymodbus/blob/504af274d920fae5e859edc7d914ce5c03a15a75/pymodbus/server/simulator/http_server.py#L263
await asyncio.sleep(0)
is the recommended method to allow other asyncio tasks to run, I thought that was in more places of the code...so I am not sure it is pointless.
There are no remaining unnecessary asycio.sleep()
to remove from the production code
Thanks.
Most places where there a asyncio.sleep() it in reality to wait for something to finish, this can mostly be replaced by "wait with timeout".