def run(self): """Run the helper threads in this class which enable streaming of STDIN/STDOUT/STDERR between the CLI and the Mesos Agent API. If a tty is requested, we take over the current terminal and put it into raw mode. We make sure to reset the terminal back to its original settings before exiting. """ # Without a TTY. if not self.tty: try: self._start_threads() self.exit_event.wait() except Exception as e: self.exception = e if self.exception: raise self.exception return # With a TTY. if util.is_windows_platform(): raise MesosException( "Running with the '--tty' flag is not supported on windows.") if not sys.stdin.isatty(): raise MesosException( "Must be running in a tty to pass the '--tty flag'.") fd = sys.stdin.fileno() oldtermios = termios.tcgetattr(fd) try: if self.interactive: tty.setraw(fd, when=termios.TCSANOW) self._window_resize(signal.SIGWINCH, None) signal.signal(signal.SIGWINCH, self._window_resize) self._start_threads() self.exit_event.wait() except Exception as e: self.exception = e termios.tcsetattr( sys.stdin.fileno(), termios.TCSAFLUSH, oldtermios) if self.exception: raise self.exception
import signal import sys import threading import time import uuid import urllib.parse from functools import partial from queue import Queue from mesos.errors import MesosException from mesos import http from mesos import recordio from mesos import util if not util.is_windows_platform(): import termios import tty class TaskIO(object): """Object used to stream I/O between a running Mesos task and the local terminal. :param task: task ID :type task: str :param cmd: a command to launch inside the task's container :type cmd: str :param args: Additional arguments for the command :type args: str :param interactive: whether to attach STDIN of the current