diff --git a/pymodbus/server/async.py b/pymodbus/server/async.py index b72eb3b53..1a446ad20 100644 --- a/pymodbus/server/async.py +++ b/pymodbus/server/async.py @@ -274,9 +274,24 @@ def StartSerialServer(context, identity=None, SerialPort(protocol, port, reactor, baudrate) reactor.run() + +def StopServer(): + """ + Helper method to stop Async Server + """ + from twisted.internet import reactor + if _is_main_thread(): + reactor.stop() + _logger.debug("Stopping main thread") + else: + reactor.callFromThread(reactor.stop) + _logger.debug("Stopping current thread") + + + #---------------------------------------------------------------------------# # Exported symbols #---------------------------------------------------------------------------# __all__ = [ - "StartTcpServer", "StartUdpServer", "StartSerialServer", + "StartTcpServer", "StartUdpServer", "StartSerialServer", "StopServer" ]