def flush(self):
        '''
        Force all queued events to be written to the events file.
        The queue will automatically be flushed at regular time intervals,
        when it grows too large, and at program exit (with the usual caveats
        of `atexit`: this won't happen if the program is killed with a
        signal or `os._exit()`).
        '''
        if self.queue:
            with open(self.filename, 'ab') as outfile:
                write_events(outfile, self.queue)
                del self.queue[:]