How to use the asciinema.async_worker.async_worker function in asciinema

To help you get started, we’ve selected a few asciinema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asciinema / asciinema / asciinema / recorder.py View on Github external
def __init__(self, writer, path, metadata, append=False):
        async_worker.__init__(self)
        self.writer = writer
        self.path = path
        self.metadata = metadata
        self.append = append
github asciinema / asciinema / asciinema / recorder.py View on Github external
def write_stdout(self, ts, data):
        self.enqueue([ts, 'o', data])

    def run(self):
        with self.writer(self.path, metadata=self.metadata, append=self.append) as w:
            for event in iter(self.queue.get, None):
                ts, etype, data = event

                if etype == 'o':
                    w.write_stdout(ts, data)
                elif etype == 'i':
                    w.write_stdin(ts, data)


class async_notifier(async_worker):
    def __init__(self):
        async_worker.__init__(self)
        self.notifier = notifier.get_notifier()

    def notify(self, text):
        self.enqueue(text)

    def perform(self, text):
        try:
            self.notifier.notify(text)
        except:
            # we catch *ALL* exceptions here because we don't want failed
            # notification to crash the recording session
            pass
github asciinema / asciinema / asciinema / recorder.py View on Github external
def __init__(self):
        async_worker.__init__(self)
        self.notifier = notifier.get_notifier()
github asciinema / asciinema / asciinema / recorder.py View on Github external
if append and os.stat(path).st_size > 0:
        time_offset = v2.get_duration(path)

    with async_writer(writer, path, full_metadata, append) as w:
        with async_notifier() as n:
            record(
                ['sh', '-c', command],
                w,
                command_env,
                rec_stdin,
                time_offset,
                n
            )


class async_writer(async_worker):
    def __init__(self, writer, path, metadata, append=False):
        async_worker.__init__(self)
        self.writer = writer
        self.path = path
        self.metadata = metadata
        self.append = append

    def write_stdin(self, ts, data):
        self.enqueue([ts, 'i', data])

    def write_stdout(self, ts, data):
        self.enqueue([ts, 'o', data])

    def run(self):
        with self.writer(self.path, metadata=self.metadata, append=self.append) as w:
            for event in iter(self.queue.get, None):