# Buggy code
def handle(self):
    """Callback when we receive any data, until self.running becomes False.
    Blocks indefinitely awaiting data.  If shutdown is required, then the
    global socket.settimeout(<seconds>) may be used, to allow timely
    checking of self.running.  However, since this also affects socket
    connects, if there are outgoing socket connections used in the same
    program, then these will be prevented, if the specfied timeout is too
    short.  Hence, this is unreliable.

    To respond to Modbus...Server.server_close() (which clears each
    handler's self.running), derive from this class to provide an
    alternative handler that awakens from time to time when no input is
    available and checks self.running.
    Use Modbus...Server( handler=... ) keyword to supply the alternative
    request handler class.

    """
    reset_frame = False
    while self.running:
        try:
            data = self.request.recv(1024)
            if not data:
                self.running = False
            if _logger.isEnabledFor(logging.DEBUG):
                _logger.debug("Handling data: " + hexlify_packets(data))
            # if not self.server.control.ListenOnly:

            units = self.server.context.slaves()
            single = self.server.context.single
            self.framer.processIncomingPacket(data, self.execute, units, single=single)
        except socket.timeout as msg:
            if _logger.isEnabledFor(logging.DEBUG):
                _logger.debug("Socket timeout occurred %s", msg)
            reset_frame = True
        except socket.error as msg:
            _logger.error("Socket error occurred %s" % msg)
            self.running = False
        except:
            _logger.error("Socket exception occurred %s" % traceback.format_exc())
            self.running = False
            reset_frame = True
        finally:
            if reset_frame:
                self.framer.resetFrame()
                reset_frame = False


# Traceback (AttributeError)
client = ModbusSerialClient(port='notexist', method='rtu')
client.connect()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "lib/python3.6/site-packages/pymodbus/client/sync.py", line 476, in connect
self.socket.interCharTimeout = self.inter_char_timeout
AttributeError: 'NoneType' object has no attribute 'interCharTimeout'

# Fixed code
def handle(self):
    """Callback when we receive any data, until self.running becomes False.
    Blocks indefinitely awaiting data.  If shutdown is required, then the
    global socket.settimeout(<seconds>) may be used, to allow timely
    checking of self.running.  However, since this also affects socket
    connects, if there are outgoing socket connections used in the same
    program, then these will be prevented, if the specfied timeout is too
    short.  Hence, this is unreliable.

    To respond to Modbus...Server.server_close() (which clears each
    handler's self.running), derive from this class to provide an
    alternative handler that awakens from time to time when no input is
    available and checks self.running.
    Use Modbus...Server( handler=... ) keyword to supply the alternative
    request handler class.

    """
    reset_frame = False
    while self.running:
        try:
            units = self.server.context.slaves()
            data = self.request.recv(1024)
            if not data:
                self.running = False
            else:
                if not isinstance(units, (list, tuple)):
                    units = [units]
                # if broadcast is enabled make sure to
                # process requests to address 0
                if self.server.broadcast_enable:
                    if 0 not in units:
                        units.append(0)

            if _logger.isEnabledFor(logging.DEBUG):
                _logger.debug("Handling data: " + hexlify_packets(data))
            single = self.server.context.single
            self.framer.processIncomingPacket(data, self.execute, units, single=single)
        except socket.timeout as msg:
            if _logger.isEnabledFor(logging.DEBUG):
                _logger.debug("Socket timeout occurred %s", msg)
            reset_frame = True
        except socket.error as msg:
            _logger.error("Socket error occurred %s" % msg)
            self.running = False
        except:
            _logger.error("Socket exception occurred %s" % traceback.format_exc())
            self.running = False
            reset_frame = True
        finally:
            if reset_frame:
                self.framer.resetFrame()
                reset_frame = False