<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _cleanup_fd(self, fd, close=False):
 """Ensure the socket socket is removed from the IOLoop, the connection stack, and futures stack. :param int fd: The fd # to cleanup """

        self._ioloop.remove_handler(fd)
        if fd in self._connections:
            try:
                self._pool_manager.free(self.pid, self._connections[fd])
            except pool.ConnectionNotFoundError:
                pass
            if close:
                self._connections[fd].close()
            del self._connections[fd]
        if fd in self._futures:
            del self._futures[fd]