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 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2015, Nicolas VERDIER (contact@n1nj4.eu) # 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 # 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 sys
import os import os
import os.path import os.path
@ -25,8 +26,19 @@ class PtyShell(object):
self.real_stdout = sys.stdout self.real_stdout = sys.stdout
def close(self): def close(self):
if self.prog is not None and self.prog.returncode is None: if self.prog is not None:
self.prog.terminate() self.prog.poll()
if self.prog.returncode is None:
try:
self.prog.terminate()
except:
pass
try:
self.prog.poll()
except:
pass
def __del__(self): def __del__(self):
self.close() self.close()