def start(self, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = self.sockets() mappings = [ (pty_stdout, io.Stream(sys.stdout)), (pty_stderr, io.Stream(sys.stderr)), ] if self.interactive: mappings.insert(0, (io.Stream(sys.stdin), pty_stdin)) pumps = [io.Pump(a, b) for (a, b) in mappings if a and b] if not self.container_info()['State']['Running']: self.client.start(self.container, **kwargs) flags = [p.set_blocking(False) for p in pumps] try: with WINCHHandler(self): self._hijack_tty(pumps) finally: if flags: for (pump, flag) in zip(pumps, flags): io.set_blocking(pump, flag)
def start(self, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = self.sockets() mappings = [ (io.Stream(sys.stdin), pty_stdin), (pty_stdout, io.Stream(sys.stdout)), (pty_stderr, io.Stream(sys.stderr)), ] pumps = [io.Pump(a, b) for (a, b) in mappings if a and b] if not self.container_info()['State']['Running']: self.client.start(self.container, **kwargs) try: flags = [io.set_blocking(p, False) for p in pumps] with WINCHHandler(self): self._hijack_tty(pumps) finally: if flags: for (pump, flag) in zip(pumps, flags): io.set_blocking(pump, flag)
def start(self): """ Present the PTY of the container inside the current process. The container must be started before this method is invoked. This will take over the current process' TTY until the container's PTY is closed. """ info = self.container_info() if not info['State']['Running']: raise Exception('Cannot attach to a stopped container') pty_stdin, pty_stdout, pty_stderr = self.sockets() pumps = [ io.Pump(sys.stdin, pty_stdin), io.Pump(pty_stdout, sys.stdout), io.Pump(pty_stderr, sys.stderr), ] try: flags = [io.set_blocking(p, False) for p in pumps] with WINCHHandler(self): self._hijack_tty(pumps) finally: for (pump, flag) in zip(pumps, flags): io.set_blocking(pump, flag)
def start(self, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = self.sockets() pumps = [] if pty_stdin and self.interactive: pumps.append(io.Pump(io.Stream(self.stdin), pty_stdin, wait_for_output=False)) if pty_stdout: pumps.append(io.Pump(pty_stdout, io.Stream(self.stdout), propagate_close=False)) if pty_stderr: pumps.append(io.Pump(pty_stderr, io.Stream(self.stderr), propagate_close=False)) if not self.container_info()["State"]["Running"]: self.client.start(self.container, **kwargs) flags = [p.set_blocking(False) for p in pumps] try: with WINCHHandler(self): self._hijack_tty(pumps) finally: if flags: for (pump, flag) in zip(pumps, flags): io.set_blocking(pump, flag)
def test_set_blocking_changes_fd_flags(): with tempfile.TemporaryFile() as f: io.set_blocking(f, False) flags = fcntl.fcntl(f, fcntl.F_GETFL) expect(flags & os.O_NONBLOCK).to.equal(os.O_NONBLOCK) io.set_blocking(f, True) flags = fcntl.fcntl(f, fcntl.F_GETFL) expect(flags & os.O_NONBLOCK).to.equal(0)
def test_set_blocking_changes_fd_flags(): with tempfile.TemporaryFile() as f: io.set_blocking(f, False) flags = fcntl.fcntl(f, fcntl.F_GETFL) expect(flags & os.O_NONBLOCK).to(equal(os.O_NONBLOCK)) io.set_blocking(f, True) flags = fcntl.fcntl(f, fcntl.F_GETFL) expect(flags & os.O_NONBLOCK).to(equal(0))
def start(self, sockets=None): pumps = self.operation.start(sockets=sockets) flags = [p.set_blocking(False) for p in pumps] try: with WINCHHandler(self): self._hijack_tty(pumps) finally: if flags: for (pump, flag) in zip(pumps, flags): io.set_blocking(pump, flag)
def start(self, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = self.sockets() pumps = [] if pty_stdin and self.interactive: pumps.append( io.Pump(io.Stream(self.stdin), pty_stdin, wait_for_output=False)) if pty_stdout: pumps.append( io.Pump(pty_stdout, io.Stream(self.stdout), propagate_close=False)) if pty_stderr: pumps.append( io.Pump(pty_stderr, io.Stream(self.stderr), propagate_close=False)) if not self.container_info()['State']['Running']: self.client.start(self.container, **kwargs) flags = [p.set_blocking(False) for p in pumps] try: with WINCHHandler(self): self._hijack_tty(pumps) finally: if flags: for (pump, flag) in zip(pumps, flags): io.set_blocking(pump, flag)
def test_set_blocking_returns_previous_state(): with tempfile.TemporaryFile() as f: io.set_blocking(f, True) expect(io.set_blocking(f, False)).to.be.true io.set_blocking(f, False) expect(io.set_blocking(f, True)).to.be.false
def test_set_blocking_returns_previous_state(): with tempfile.TemporaryFile() as f: io.set_blocking(f, True) expect(io.set_blocking(f, False)).to(be_true) io.set_blocking(f, False) expect(io.set_blocking(f, True)).to(be_false)