def is_valid_fd(fd): """Check whether the passed in fd is open""" try: fcntl.fcntl(fd, fcntl.F_GETFD) return True except: return False