mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-10 00:50:56 +08:00
#9 properly terminate all child processes
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
# OR CONDITIONS OF ANY KIND, either express or implied. See the License for
|
# OR CONDITIONS OF ANY KIND, either express or implied. See the License for
|
||||||
# the specific language governing permissions and limitations under the License.
|
# the specific language governing permissions and limitations under the License.
|
||||||
import psutil
|
import psutil
|
||||||
|
import logging
|
||||||
|
|
||||||
from flask import make_response, request
|
from flask import make_response, request
|
||||||
from requests import get, post, put
|
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.cellxgene_exception import CellxgeneException
|
||||||
from cellxgene_gateway.util import current_time_stamp
|
from cellxgene_gateway.util import current_time_stamp
|
||||||
|
|
||||||
|
|
||||||
class CacheEntry:
|
class CacheEntry:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -77,10 +78,18 @@ class CacheEntry:
|
|||||||
def terminate(self):
|
def terminate(self):
|
||||||
pid = self.pid
|
pid = self.pid
|
||||||
if pid != None and self.status != "terminated":
|
if pid != None and self.status != "terminated":
|
||||||
|
terminated = []
|
||||||
|
def on_terminate(p):
|
||||||
|
terminated.append(p.pid)
|
||||||
p = psutil.Process(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.terminate()
|
||||||
p = psutil.Process(pid + 2)
|
psutil.wait_procs([p], callback=on_terminate)
|
||||||
p.terminate()
|
logging.getLogger("cellxgene_gateway").info(f"terminated {terminated}")
|
||||||
self.status = "terminated"
|
self.status = "terminated"
|
||||||
|
|
||||||
def serve_content(self, path):
|
def serve_content(self, path):
|
||||||
|
|||||||
Reference in New Issue
Block a user