Skip to content

Commit

Permalink
New helper function to help stop Asynchronous server are being added.
Browse files Browse the repository at this point in the history
Calling this helper function will kill the main thread
  • Loading branch information
rahul committed Nov 24, 2017
1 parent 2bbb5e5 commit f111f2e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pymodbus/server/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,23 @@ def StartSerialServer(context, identity=None,
SerialPort(protocol, port, reactor, baudrate)
reactor.run()


def _stop_server(is_mainthread=True):
from twisted.internet import reactor
if _is_main_thread():
reactor.stop()
else:
reactor.callFromThread(reactor.stop)
_logger.debug("Stopping main thread")


StopTcpServer = StopSerialServer = _stop_server


#---------------------------------------------------------------------------#
# Exported symbols
#---------------------------------------------------------------------------#
__all__ = [
"StartTcpServer", "StartUdpServer", "StartSerialServer",
"StartTcpServer", "StartUdpServer", "StartSerialServer", "StopTcpServer",
"StopSerialServer"
]

0 comments on commit f111f2e

Please sign in to comment.