Skip to content

Commit

Permalink
#84: Stop Asynchronous Server (#243)
Browse files Browse the repository at this point in the history
* New helper function to help stop Asynchronous server are being added.
Calling this helper function will kill the main thread

* #84: Removing redundant parameters to method _is_main_thread

* #84: Fixed loggers

* #84: Retaining one generic StopServer command that will cater to both TCP and Seriel Server

* #84 Add docuementation to StopServer helper function
  • Loading branch information
rahulraghu94 authored and dhoomakethu committed Nov 25, 2017
1 parent 27a834e commit b1b9e4f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pymodbus/server/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,24 @@ def StartSerialServer(context, identity=None,
SerialPort(protocol, port, reactor, baudrate)
reactor.run(installSignalHandlers=_is_main_thread())


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"
]

0 comments on commit b1b9e4f

Please sign in to comment.