Skip to content

Commit dbe3cd5

Browse files
committed
eliminate asyncio.sleep() and replace time.sleep() with a timeout
1 parent c884f4b commit dbe3cd5

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

pymodbus/server/async_io.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import asyncio
66
import os
7-
import time
87
import traceback
98
from contextlib import suppress
109

@@ -569,10 +568,6 @@ async def async_stop(cls):
569568
if not cls.active_server:
570569
raise RuntimeError("ServerAsyncStop called without server task active.")
571570
await cls.active_server.shutdown()
572-
if os.name == "nt":
573-
await asyncio.sleep(1)
574-
else:
575-
await asyncio.sleep(0)
576571
cls.active_server = None
577572

578573
@classmethod
@@ -584,11 +579,8 @@ def stop(cls):
584579
if not cls.active_server.loop.is_running():
585580
Log.info("ServerStop called with loop stopped.")
586581
return
587-
asyncio.run_coroutine_threadsafe(cls.async_stop(), cls.active_server.loop)
588-
if os.name == "nt":
589-
time.sleep(10)
590-
else:
591-
time.sleep(0.1)
582+
future = asyncio.run_coroutine_threadsafe(cls.async_stop(), cls.active_server.loop)
583+
future.result(timeout=10 if os.name == 'nt' else 0.1)
592584

593585

594586
async def StartAsyncTcpServer( # pylint: disable=invalid-name,dangerous-default-value

0 commit comments

Comments
 (0)