'Utility method to close an ``fd``.
If ``fd`` is a file-like object, we close it directly; otherwise
we use `os.close`.
This method is provided for use by `IOLoop` subclasses (in
implementations of ``IOLoop.close(all_fds=True)`` and should
not generally be used by application code.
.. versionadded:: 4.0'

def close_fd(self, fd):

    try:
        try:
            fd.close()
        except AttributeError:
            os.close(fd)
    except OSError:
        pass
