Skip to content

Commit a152762

Browse files
authored
eliminate asyncio.sleep() and replace time.sleep() with a timeout (#2034)
1 parent fe809d9 commit a152762

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

@@ -578,10 +577,6 @@ async def async_stop(cls):
578577
if not cls.active_server:
579578
raise RuntimeError("ServerAsyncStop called without server task active.")
580579
await cls.active_server.server.shutdown()
581-
if os.name == "nt":
582-
await asyncio.sleep(1)
583-
else:
584-
await asyncio.sleep(0)
585580
cls.active_server = None
586581

587582
@classmethod
@@ -593,11 +588,8 @@ def stop(cls):
593588
if not cls.active_server.loop.is_running():
594589
Log.info("ServerStop called with loop stopped.")
595590
return
596-
asyncio.run_coroutine_threadsafe(cls.async_stop(), cls.active_server.loop)
597-
if os.name == "nt":
598-
time.sleep(10)
599-
else:
600-
time.sleep(0.1)
591+
future = asyncio.run_coroutine_threadsafe(cls.async_stop(), cls.active_server.loop)
592+
future.result(timeout=10 if os.name == 'nt' else 0.1)
601593

602594

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

0 commit comments

Comments
 (0)