pymodbus-dev / pymodbus

A full modbus protocol written in python
Other
2.26k stars 922 forks source link

Remove asyncio.sleep from production code (not test/examples) #1998

Closed janiversen closed 7 months ago

janiversen commented 7 months ago

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".

janiversen commented 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)
alexrudd2 commented 7 months ago

These are the remaining uses in production code:

janiversen commented 7 months ago
   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.

alexrudd2 commented 7 months ago

There are no remaining unnecessary asycio.sleep() to remove from the production code

janiversen commented 7 months ago

Thanks.