Skip to content

Commit

Permalink
Merge pull request #99 from joshkel/master
Browse files Browse the repository at this point in the history
Lazily initialize InstallManagementConsole
  • Loading branch information
bashwork committed Sep 26, 2015
2 parents 335f646 + 977551d commit 2afc1e7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pymodbus/server/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from pymodbus.exceptions import NoSuchSlaveException
from pymodbus.transaction import ModbusSocketFramer, ModbusAsciiFramer
from pymodbus.pdu import ModbusExceptions as merror
from pymodbus.internal.ptwisted import InstallManagementConsole

#---------------------------------------------------------------------------#
# Logging
Expand Down Expand Up @@ -215,7 +214,9 @@ def StartTcpServer(context, identity=None, address=None, console=False, **kwargs
address = address or ("", Defaults.Port)
framer = ModbusSocketFramer
factory = ModbusServerFactory(context, framer, identity, **kwargs)
if console: InstallManagementConsole({'factory': factory})
if console:
from pymodbus.internal.ptwisted import InstallManagementConsole
InstallManagementConsole({'factory': factory})

_logger.info("Starting Modbus TCP Server on %s:%s" % address)
reactor.listenTCP(address[1], factory, interface=address[0])
Expand Down Expand Up @@ -262,7 +263,9 @@ def StartSerialServer(context, identity=None,

_logger.info("Starting Modbus Serial Server on %s" % port)
factory = ModbusServerFactory(context, framer, identity, **kwargs)
if console: InstallManagementConsole({'factory': factory})
if console:
from pymodbus.internal.ptwisted import InstallManagementConsole
InstallManagementConsole({'factory': factory})

protocol = factory.buildProtocol(None)
SerialPort.getHost = lambda self: port # hack for logging
Expand Down

0 comments on commit 2afc1e7

Please sign in to comment.