Try as much as possible to read process status

This commit is contained in:
Oleksii Shevchuk 2017-03-03 13:34:38 +02:00 committed by Oleksii Shevchuk
parent 45ac2bf02e
commit 1e01b0ad0a
1 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Nicolas VERDIER (contact@n1nj4.eu)
# Pupy is under the BSD 3-Clause license. see the LICENSE file at the root of the project for the detailed licence terms
import sys
import os
import os.path
@ -25,8 +26,19 @@ class PtyShell(object):
self.real_stdout = sys.stdout
def close(self):
if self.prog is not None and self.prog.returncode is None:
self.prog.terminate()
if self.prog is not None:
self.prog.poll()
if self.prog.returncode is None:
try:
self.prog.terminate()
except:
pass
try:
self.prog.poll()
except:
pass
def __del__(self):
self.close()