Skip to content

eliminate asyncio.sleep() and replace time.sleep() with a timeout #2034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions pymodbus/server/async_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import asyncio
import os
import time
import traceback
from contextlib import suppress

Expand Down Expand Up @@ -578,10 +577,6 @@ async def async_stop(cls):
if not cls.active_server:
raise RuntimeError("ServerAsyncStop called without server task active.")
await cls.active_server.server.shutdown()
if os.name == "nt":
await asyncio.sleep(1)
else:
await asyncio.sleep(0)
cls.active_server = None

@classmethod
Expand All @@ -593,11 +588,8 @@ def stop(cls):
if not cls.active_server.loop.is_running():
Log.info("ServerStop called with loop stopped.")
return
asyncio.run_coroutine_threadsafe(cls.async_stop(), cls.active_server.loop)
if os.name == "nt":
time.sleep(10)
else:
time.sleep(0.1)
future = asyncio.run_coroutine_threadsafe(cls.async_stop(), cls.active_server.loop)
future.result(timeout=10 if os.name == 'nt' else 0.1)


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