Skip to content

Commit

Permalink
Merge branch 'pylint_fix' of https://github.com/pytorch/serve into py…
Browse files Browse the repository at this point in the history
…lint_fix
  • Loading branch information
shivamshriwas committed Aug 24, 2020
2 parents 4666c68 + b741803 commit f6441a5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public CompletableFuture<HttpResponseStatus> modelChanged(Model model, boolean i
if (workerProcess != null && workerProcess.isAlive()) {
boolean workerDestroyed = false;
try {
// TODO : Add OS specific handling for windows support.
String cmd = String.format("kill -9 %s", workerProcess.pid());
String cmd = String.format(getKillCmd(), workerProcess.pid());
Process workerKillProcess = Runtime.getRuntime().exec(cmd, null, null);
workerDestroyed =
workerKillProcess.waitFor(
Expand Down Expand Up @@ -156,6 +155,17 @@ public CompletableFuture<HttpResponseStatus> modelChanged(Model model, boolean i
}
}

private String getKillCmd() {
String operatingSystem = System.getProperty("os.name").toLowerCase();
String killCMD;
if (operatingSystem.indexOf("win") >= 0) {
killCMD = "taskkill /f /PID %s";
} else {
killCMD = "kill -9 %s";
}
return killCMD;
}

private void addThreads(
List<WorkerThread> threads,
Model model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ private Metric createMetric(String metricName, String requestId) {

@SuppressWarnings("unchecked")
private void modifyEnv(String key, String val) throws ReflectiveOperationException {
Map<String, String> env = System.getenv();
Field field = env.getClass().getDeclaredField("m");
field.setAccessible(true);
((Map<String, String>) field.get(env)).put(key, val);
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
Field f = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
f.setAccessible(true);
Map<String, String> cienv = (Map<String, String>) f.get(null);
cienv.put(key, val);
} else {
Map<String, String> env = System.getenv();
Field field = env.getClass().getDeclaredField("m");
field.setAccessible(true);
((Map<String, String>) field.get(env)).put(key, val);
}
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion requirements/developer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pytest
pylint
pytest-mock
pytest-cov
nvgpu
nvgpu
numpy
2 changes: 1 addition & 1 deletion test/regression_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ install_torchserve_from_source() {
cd serve
echo "Installing torchserve torch-model-archiver from source"
./scripts/install_from_src
pip install -r requirements/developer.txt
pip install -U -r requirements/developer.txt
pip install transformers
echo "TS Branch : " "$(git rev-parse --abbrev-ref HEAD)" >> $3
echo "TS Branch Commit Id : " "$(git rev-parse HEAD)" >> $3
Expand Down

0 comments on commit f6441a5

Please sign in to comment.