#9 properly terminate all child processes

This commit is contained in:
Alok Saldanha
2019-10-29 21:19:18 -04:00
parent 455e0cd087
commit 66f7a6b5a7

View File

@@ -7,6 +7,8 @@
# OR CONDITIONS OF ANY KIND, either express or implied. See the License for
# the specific language governing permissions and limitations under the License.
import psutil
import logging
from flask import make_response, request
from requests import get, post, put
@@ -14,7 +16,6 @@ from cellxgene_gateway import env
from cellxgene_gateway.cellxgene_exception import CellxgeneException
from cellxgene_gateway.util import current_time_stamp
class CacheEntry:
def __init__(
self,
@@ -77,10 +78,18 @@ class CacheEntry:
def terminate(self):
pid = self.pid
if pid != None and self.status != "terminated":
terminated = []
def on_terminate(p):
terminated.append(p.pid)
p = psutil.Process(pid)
children = p.children()
for child in children:
child.terminate()
psutil.wait_procs(children, callback=on_terminate)
terminated.append(p.pid)
p.terminate()
p = psutil.Process(pid + 2)
p.terminate()
psutil.wait_procs([p], callback=on_terminate)
logging.getLogger("cellxgene_gateway").info(f"terminated {terminated}")
self.status = "terminated"
def serve_content(self, path):