Skip to content

Commit

Permalink
Use psutil to kill IPS
Browse files Browse the repository at this point in the history
  • Loading branch information
ovidner committed Jan 26, 2024
1 parent 8c4c4bf commit f7b3404
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions conda-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
version: 1
metadata:
content_hash:
win-64: 8fa1b3cc591b6d4e5f0acaa41be6a812f197a328e7c81636bed15c381495b7db
win-64: 318bbf1e56945f73c9b5e42d030e8f4451b6470e6209f64a95ae6ba81c869f96
channels:
- url: pytorch
used_env_vars: []
Expand Down Expand Up @@ -2660,8 +2660,8 @@ package:
hash:
md5: 17e48538806e7c682d2ffcbd5c9f9aa0
sha256: 77760f2ce0d2be9339d94d0fb5b3d102659355563f5b6471a1231525e63ff581
category: dev
optional: true
category: main
optional: false
- name: pthread-stubs
version: '0.4'
manager: conda
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"msgpack",
"numpy",
"plotly",
"psutil",
"pydantic",
"matplotlib",
"panel",
Expand Down
11 changes: 9 additions & 2 deletions src/autopack/ips_communication/ips_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import msgpack
import numpy as np
import psutil
import zmq
from pydantic import BaseModel

Expand Down Expand Up @@ -55,6 +56,12 @@ def unpack(payload: bytes) -> Any:
return msgpack.unpackb(base64.b64decode(payload))


def kill_all_ips_procs():
for proc in psutil.process_iter(attrs=["name"]):
if proc.name() == "IPS.exe":
proc.kill()


class IPSError(RuntimeError):
pass

Expand All @@ -71,7 +78,7 @@ def __init__(self, ips_path=None, port=24768):
self.connected = False

def start(self):
subprocess.run(["taskkill", "/F", "/IM", "IPS.exe"])
kill_all_ips_procs()
logger.info(f"Starting IPS at {self.ips_path}")
self.process = subprocess.Popen(
["IPS.exe", "-port", str(self.port)],
Expand Down Expand Up @@ -154,7 +161,7 @@ def call(self, func_name: str, *args: Any, return_result: bool = True) -> Any:
return self.eval(command)

def kill(self):
subprocess.run(["taskkill", "/F", "/IM", "IPS.exe"])
self.process.kill()
self.connected = False

def _wait_socket(self, flags, timeout=1000):
Expand Down

0 comments on commit f7b3404

Please sign in to comment.