def output_stream_generator(self, *args, **kwargs):
        from fabric_bolt.task_runners import backend

        self.process = subprocess.Popen(
            backend.build_command(self.deployment.stage.project, self.deployment, self.request.session, False),
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            stdin=subprocess.PIPE,
            shell=True,
            executable=getattr(settings, 'SHELL', '/bin/sh'),
            close_fds=True,
        )

        fd = self.process.stdout.fileno()
        fl = fcntl.fcntl(fd, fcntl.F_GETFL)
        fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        all_output = ''
        while True:
            try:
                nextline = self.process.stdout.read()
            except __HOLE__ as e:
                print e
                nextline = ''

            if nextline == '' and self.process.poll() != None:
                break

            all_output += nextline

            if nextline:
                self.broadcast_event('output', {'status': 'pending', 'lines': str(nextline)})
            time.sleep(0.00001)

            sys.stdout.flush()

        self.deployment.status = self.deployment.SUCCESS if self.process.returncode == 0 else self.deployment.FAILED

        self.deployment.output = all_output
        self.deployment.save()

        self.broadcast_event('output', {'status': self.deployment.status})

        self.disconnect()
dataset/ETHPy150Open fabric-bolt/fabric-bolt/fabric_bolt/task_runners/socketio/sockets.py/ChatNamespace.output_stream_generator