def close(self):
        """Close all resources and unpublish service"""
        if self.log is not None:
            self.log.info("%s: closing..." % (self.device, ))
        self.alive = False
        self.unpublish()
        if self.server_socket:
            self.server_socket.close()
        if self.socket:
            self.handle_disconnect()
        self.serial.close()
        if self.on_close is not None:
            # ensure it is only called once
            callback = self.on_close
            self.on_close = None
            callback(self)
dataset/ETHPy150Open pyserial/pyserial/examples/port_publisher.py/Forwarder.close/original