@@ -125,8 +125,7 @@ def connection_lost(self, call_exc):
125125 _logger .debug (txt )
126126
127127 self .running = False
128-
129- except Exception as exc : # pragma: no cover pylint: disable=broad-except
128+ except Exception as exc : # pylint: disable=broad-except
130129 txt = (
131130 f"Datastore unable to fulfill request: { exc } ; { traceback .format_exc ()} "
132131 )
@@ -858,9 +857,9 @@ async def StartTcpServer( # pylint: disable=invalid-name,dangerous-default-valu
858857 :param address: An optional (interface, port) to bind to.
859858 :param custom_functions: An optional list of custom function classes
860859 supported by server instance.
861- :param defer_start: if set, a coroutine which can be started and stopped
862- will be returned. Otherwise, the server will be immediately spun
863- up without the ability to shut it off from within the asyncio loop
860+ :param defer_start: if set, the server object will be returned ready to start.
861+ Otherwise, the server will be immediately spun
862+ up without the ability to shut it off
864863 :param kwargs: The rest
865864 :return: an initialized but inactive server object coroutine
866865 """
@@ -870,10 +869,9 @@ async def StartTcpServer( # pylint: disable=invalid-name,dangerous-default-valu
870869 for func in custom_functions :
871870 server .decoder .register (func ) # pragma: no cover
872871
873- if not defer_start :
874- await server .serve_forever ()
875-
876- return server
872+ if defer_start :
873+ return server
874+ await server .serve_forever ()
877875
878876
879877async def StartTlsServer ( # pylint: disable=invalid-name,dangerous-default-value,too-many-arguments
@@ -906,9 +904,9 @@ async def StartTlsServer( # pylint: disable=invalid-name,dangerous-default-valu
906904 :param allow_reuse_port: Whether the server will allow the reuse of a port.
907905 :param custom_functions: An optional list of custom function classes
908906 supported by server instance.
909- :param defer_start: if set, a coroutine which can be started and stopped
910- will be returned. Otherwise, the server will be immediately spun
911- up without the ability to shut it off from within the asyncio loop
907+ :param defer_start: if set, the server object will be returned ready to start.
908+ Otherwise, the server will be immediately spun
909+ up without the ability to shut it off
912910 :param kwargs: The rest
913911 :return: an initialized but inactive server object coroutine
914912 """
@@ -931,10 +929,9 @@ async def StartTlsServer( # pylint: disable=invalid-name,dangerous-default-valu
931929 for func in custom_functions :
932930 server .decoder .register (func ) # pragma: no cover
933931
934- if not defer_start :
935- await server .serve_forever ()
936-
937- return server
932+ if defer_start :
933+ return server
934+ await server .serve_forever ()
938935
939936
940937async def StartUdpServer ( # pylint: disable=invalid-name,dangerous-default-value
@@ -952,7 +949,9 @@ async def StartUdpServer( # pylint: disable=invalid-name,dangerous-default-valu
952949 :param address: An optional (interface, port) to bind to.
953950 :param custom_functions: An optional list of custom function classes
954951 supported by server instance.
955- :param defer_start: start with delay
952+ :param defer_start: if set, the server object will be returned ready to start.
953+ Otherwise, the server will be immediately spun
954+ up without the ability to shut it off
956955 :param kwargs:
957956 """
958957 framer = kwargs .pop ("framer" , ModbusSocketFramer )
@@ -961,16 +960,16 @@ async def StartUdpServer( # pylint: disable=invalid-name,dangerous-default-valu
961960 for func in custom_functions :
962961 server .decoder .register (func ) # pragma: no cover
963962
964- if not defer_start :
965- await server .serve_forever () # pragma: no cover
966-
967- return server
963+ if defer_start :
964+ return server
965+ await server .serve_forever ()
968966
969967
970968async def StartSerialServer ( # pylint: disable=invalid-name,dangerous-default-value
971969 context = None ,
972970 identity = None ,
973971 custom_functions = [],
972+ defer_start = False ,
974973 ** kwargs ,
975974): # pragma: no cover
976975 """Start and run a serial modbus server.
@@ -979,25 +978,22 @@ async def StartSerialServer( # pylint: disable=invalid-name,dangerous-default-v
979978 :param identity: An optional identify structure
980979 :param custom_functions: An optional list of custom function classes
981980 supported by server instance.
981+ :param defer_start: if set, the server object will be returned ready to start.
982+ Otherwise, the server will be immediately spun
983+ up without the ability to shut it off
982984 :param kwargs: The rest
983985 """
984986 framer = kwargs .pop ("framer" , ModbusAsciiFramer )
985987 server = ModbusSerialServer (context , framer , identity = identity , ** kwargs )
986988 for func in custom_functions :
987989 server .decoder .register (func )
990+
991+ if defer_start :
992+ return server
988993 await server .start ()
989994 await server .serve_forever ()
990995
991996
992- def StopServer (): # pylint: disable=invalid-name
993- """Stop Async Server."""
994- warnings .warn (
995- "deprecated API for asyncio. Call server_close() on "
996- "server object returned by StartXxxServer" ,
997- DeprecationWarning ,
998- )
999-
1000-
1001997# --------------------------------------------------------------------------- #
1002998# Exported symbols
1003999# --------------------------------------------------------------------------- #
0 commit comments