Skip to content

Commit

Permalink
Add psutil to correct requirements.txt, make sure to kill Unity proce…
Browse files Browse the repository at this point in the history
…ss only if it is a child process of the controller (MCS-1817).
  • Loading branch information
rartiss55 committed Aug 29, 2023
1 parent 9781cd9 commit 28c6cc0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ opencv-python==4.5.4.60; python_version>="3.10"
pep8-naming==0.13.3
pre-commit==2.21.0; python_version<"3.8"
pre-commit==3.2.2; python_version>="3.8"
psutil==5.9.5
pydantic==1.10.7
recommonmark==0.7.1
requests==2.31.0
Expand Down
17 changes: 9 additions & 8 deletions webenabled/mcsweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,25 @@ def handle_keypress():
@app.route("/exit_unity", methods=["POST"])
def exit_unity():
app.logger.info("=" * 30)
mcs_interface, unique_id = get_mcs_interface(request, "exit unity")
mcs_interface, unique_id = get_mcs_interface(request, "Exit Unity")
if mcs_interface is None:
app.logger.warn("Cannot load MCS interface")
return

controller_pid = mcs_interface.get_controller_pid()
unity_proc_name = 'MCS-AI2-THOR'

app.logger.info(
"Attempting to clean up processes after browser has been closed.")

for p in psutil.process_iter(['name']):
if p.info['name'] == unity_proc_name:
app.logger.info(f"Found Unity process: {p}, will attempt to end.")
p.kill()

for p in psutil.process_iter(['pid']):
if p.info['pid'] == controller_pid:
children = p.children(recursive=True)
for c_process in children:
app.logger.info(
f"Found child process of controller: {c_process}, "
f"will attempt to end.")
c_process.kill()

app.logger.info(
f"Found controller process: {p}, will attempt to end.")
p.kill()
Expand All @@ -161,7 +162,7 @@ def exit_unity():
unique_id = request.cookies.get("uniq_id")

app.logger.info(
f"Clear user session {unique_id}")
f"Clear user session for: {unique_id}")
del session[unique_id]

resp = jsonify(
Expand Down
1 change: 1 addition & 0 deletions webenabled/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ flake8==5.0.4; python_version<"3.8"
flake8==6.0.0; python_version>="3.8"
isort==5.11.5; python_version<"3.8"
isort==5.12.0; python_version>="3.8"
psutil==5.9.5
pytest==7.3.0

0 comments on commit 28c6cc0

Please sign in to comment.