# Buggy code
def close(self, force=False):
    """
    Close the communication with the terminal's child and terminate it.
    """
    if not self.closed:
        os.close(self.child_fd)
        os.close(self.child_fde)
        time.sleep(0.1)
        if not self.terminate(force):
            raise TerminalException("Failed to terminate child process.")
        self.child_fd = self.child_fde = None
        self.closed = True


# Traceback (OSError)
2014-02-12 13:06:50,022 [salt.utils.cloud ][DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -oPasswordAuthentication=no -oChallengeResponseAuthentica
tion=no -oPubkeyAuthentication=yes -oKbdInteractiveAuthentication=no -i /mnt/stackdio_root/stackdio/storage/cloud/aws-qatp/id_rsa root@10.44.13.132 '/tmp/.saltcloud/deploy.sh -c /tmp/.saltcloud -D git 3a894d76069
9ab155bc63a3e35e6730f87cc7d8c'"
2014-02-12 13:06:50,024 [salt.utils.vt    ][WARNING ] Failed to spawn the VT: out of pty devices
Traceback (most recent call last):
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/vt.py", line 198, in __init__
self._spawn()
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/vt.py", line 377, in _spawn
self.pid, self.child_fd, self.child_fde = self.__fork_ptys()
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/vt.py", line 451, in __fork_ptys
stderr_parent_fd, stderr_child_fd = pty.openpty()
File "/usr/lib/python2.7/pty.py", line 29, in openpty
master_fd, slave_name = _open_terminal()
File "/usr/lib/python2.7/pty.py", line 70, in _open_terminal
raise os.error, 'out of pty devices'
OSError: out of pty devices
2014-02-12 13:06:50,025 [salt.utils.cloud ][ERROR   ] Failed to execute command '/tmp/.saltcloud/deploy.sh -c /tmp/.saltcloud -D git 3a894d760699ab155bc63a3e35e6730f87cc7d8c': Failed to spawn the VT. Error: out of pty devices
Traceback (most recent call last):
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/cloud.py", line 1235, in root_cmd
stream_stderr=kwargs.get('display_ssh_output', True)
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/vt.py", line 207, in __init__
'Failed to spawn the VT. Error: {0}'.format(err)
TerminalException: Failed to spawn the VT. Error: out of pty devices
2014-02-12 13:06:50,026 [salt.cloud       ][ERROR   ] Failed to deploy 'test-spot-dn-126'. Error: Executing the command '/tmp/.saltcloud/deploy.sh -c /tmp/.saltcloud -D git 3a894d760699ab155bc63a3e35e6730f87cc7d8c' failed
Traceback (most recent call last):
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/cloud/__init__.py", line 1699, in create_multiprocessing
local_master=parallel_data['local_master']
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/cloud/__init__.py", line 854, in create
output = self.clouds[func](vm_)
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/cloud/clouds/ec2.py", line 1576, in create
deployed = salt.utils.cloud.deploy_script(**deploy_kwargs)
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/cloud.py", line 864, in deploy_script
deploy_command
SaltCloudSystemExit: Executing the command '/tmp/.saltcloud/deploy.sh -c /tmp/.saltcloud -D git 3a894d760699ab155bc63a3e35e6730f87cc7d8c' failed

# Fixed code
def close(self, force=False):
    """
    Close the communication with the terminal's child and terminate it.
    """
    if not self.closed:
        if self.child_fd is not None:
            os.close(self.child_fd)
        if self.child_fde is not None:
            os.close(self.child_fde)
        time.sleep(0.1)
        if not self.terminate(force):
            raise TerminalException("Failed to terminate child process.")
        self.child_fd = self.child_fde = None
        self.closed = True