Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ptyprocess/ptyprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,12 @@ def isatty(self):
methods such as setecho(), setwinsize(), getwinsize() may raise an
IOError. '''

return os.isatty(self.fd)
if self.closed or self.fd < 0:
return False
try:
return os.isatty(self.fd)
except OSError:
return False

def waitnoecho(self, timeout=None):
'''Wait until the terminal ECHO flag is set False.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,9 @@ def test_pass_fds(self):

with open(temp_file_name, 'r') as temp_file_r:
assert temp_file_r.read() == 'hello'

def test_isatty_when_closed(self):
p = PtyProcess.spawn(['true'])
self.assertTrue(p.isatty())
p.close()
self.assertFalse(p.isatty())