Skip to content

Commit

Permalink
Server_async[udp], solve 3.1.1 problem. (#1564)
Browse files Browse the repository at this point in the history
This reverts commit 755dcf3.
  • Loading branch information
janiversen authored Jun 1, 2023
1 parent acbb864 commit 3fc5d37
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pymodbus/server/async_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ def __init__(
self.protocol = None
self.endpoint = None
self.on_connection_terminated = None
self.stop_serving = self.loop.create_future()
# asyncio future that will be done once server has started
self.serving = asyncio.Future()
self.factory_parms = {
Expand All @@ -841,6 +842,7 @@ async def serve_forever(self):
raise RuntimeError(exc) from exc
Log.info("Server(UDP) listening.")
self.serving.set_result(True)
await self.stop_serving
else:
raise RuntimeError(
"Can't call serve_forever on an already running server object"
Expand All @@ -854,10 +856,13 @@ async def server_close(self):
"""Close server."""
if self.endpoint:
self.endpoint.running = False
if not self.stop_serving.done():
self.stop_serving.set_result(True)
if self.endpoint is not None and self.endpoint.handler_task is not None:
self.endpoint.handler_task.cancel()
if self.protocol is not None:
self.protocol.close()
# TBD await self.protocol.wait_closed()
self.protocol = None


Expand Down

0 comments on commit 3fc5d37

Please sign in to comment.