Skip to content

Commit

Permalink
Reconect_delay == 0, do not reconnect. (#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Oct 6, 2023
1 parent ced082d commit 1738be2
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 22 deletions.
3 changes: 0 additions & 3 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ def __init__( # pylint: disable=too-many-arguments
self.params.close_comm_on_error = bool(close_comm_on_error)
self.params.strict = bool(strict)
self.params.broadcast_enable = bool(broadcast_enable)
self.params.reconnect_delay = int(reconnect_delay)
self.reconnect_delay_max = int(reconnect_delay_max)
self.on_reconnect_callback = on_reconnect_callback
self.retry_on_empty: int = 0
self.no_resend_on_retry = no_resend_on_retry
Expand All @@ -124,7 +122,6 @@ def __init__( # pylint: disable=too-many-arguments
self.transaction = DictTransactionManager(
self, retries=retries, retry_on_empty=retry_on_empty, **kwargs
)
self.reconnect_delay = self.params.reconnect_delay
self.reconnect_delay_current = self.params.reconnect_delay
self.use_udp = False
self.state = ModbusTransactionState.IDLE
Expand Down
4 changes: 0 additions & 4 deletions pymodbus/client/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ def connected(self):

async def connect(self) -> bool:
"""Connect Async client."""
# if reconnect_delay_current was set to 0 by close(), we need to set it back again
# so this instance will work
self.reset_delay()

# force reconnect if required:
Log.debug("Connecting to {}.", self.comm_params.host)
return await self.transport_connect()

Expand Down
5 changes: 0 additions & 5 deletions pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ def __init__(

async def connect(self) -> bool:
"""Initiate connection to start client."""

# if reconnect_delay_current was set to 0 by close(), we need to set it back again
# so this instance will work
self.reset_delay()

# force reconnect if required:
Log.debug(
"Connecting to {}:{}.",
self.comm_params.host,
Expand Down
5 changes: 0 additions & 5 deletions pymodbus/client/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ def __init__(

async def connect(self) -> bool:
"""Initiate connection to start client."""

# if reconnect_delay_current was set to 0 by close(), we need to set it back again
# so this instance will work
self.reset_delay()

# force reconnect if required:
Log.debug(
"Connecting to {}:{}.",
self.comm_params.host,
Expand Down
4 changes: 0 additions & 4 deletions pymodbus/client/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ async def connect(self) -> bool:
:meta private:
"""
# if reconnect_delay_current was set to 0 by close(), we need to set it back again
# so this instance will work
self.reset_delay()

# force reconnect if required:
Log.debug(
"Connecting to {}:{}.",
self.comm_params.host,
Expand Down
6 changes: 5 additions & 1 deletion pymodbus/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ def connection_lost(self, reason: Exception):
return
Log.debug("Connection lost {} due to {}", self.comm_params.comm_name, reason)
self.transport_close(intern=True)
if not self.is_server and not self.listener:
if (
not self.is_server
and not self.listener
and self.comm_params.reconnect_delay
):
self.reconnect_task = asyncio.create_task(self.do_reconnect())
self.callback_disconnected(reason)

Expand Down
2 changes: 2 additions & 0 deletions test/sub_transport/test_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ async def test_connected(self, client, server, use_comm_type):
)
async def test_connected_multiple(self, client, server):
"""Test connection and data exchange."""
client.comm_params.reconnect_delay = 0.0
assert await server.transport_listen()
assert await client.transport_connect()
await asyncio.sleep(0.5)
Expand Down Expand Up @@ -174,6 +175,7 @@ async def test_connected_multiple(self, client, server):
assert server2_connected.recv_buffer == test2_data + test_data
client2.transport_close()
server.transport_close()
await asyncio.sleep(0.5)
assert not server.active_connections


Expand Down

0 comments on commit 1738be2

Please sign in to comment.