Skip to content

Plugin to pipe stdout/stderr to a log event #7202

Description

@mrocklin

Folks sometimes want stdout and stderr sent to the client. This is maybe pretty easy with ...

  1. Teeing off sys.stdout/stderr as in https://stackoverflow.com/questions/616645/how-to-duplicate-sys-stdout-to-a-log-file
  2. Dropping the results into the print log event
  3. All withing a WorkerPlugin

Maybe something like this for stdout?

class Tee(object):
    def __init__(self, worker):
        self.stdout = sys.stdout
        self.worker = worker
        sys.stdout = self
    def close(self):
        sys.stdout = self.stdout
    def write(self, data):
        self.worker.log_event("print", data)
        self.stdout.write(data)
    def flush(self):
        self.file.flush()

class StdOut(WorkerPlugin):
    def start(self, worker):
        self.tee = Tee(worker)

    def close(self):
        self.tee.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions