'Closes the stream.'

def close(self):

    self.acquire()
    try:
        try:
            if self.stream:
                try:
                    self.flush()
                finally:
                    stream = self.stream
                    self.stream = None
                    if hasattr(stream, 'close'):
                        stream.close()
        finally:
            StreamHandler.close(self)
    finally:
        self.release()
