Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit 62d5812

Browse files
authored
quick fix kill command under windows (#3106)
1 parent 604f843 commit 62d5812

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

nni/tools/nnictl/command_utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def check_output_command(file_path, head=None, tail=None):
3434
def kill_command(pid):
3535
"""kill command"""
3636
if sys.platform == 'win32':
37-
psutil.Process(pid).terminate()
37+
process = psutil.Process(pid=pid)
38+
process.send_signal(signal.CTRL_BREAK_EVENT)
3839
else:
3940
cmds = ['kill', str(pid)]
4041
call(cmds)

ts/nni_manager/main.ts

+7-16
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,7 @@ mkDirP(getLogDir())
179179
console.error(`Failed to create log dir: ${err.stack}`);
180180
});
181181

182-
function getStopSignal(): any {
183-
return 'SIGTERM';
184-
}
185-
186-
function getCtrlCSignal(): any {
187-
return 'SIGINT';
188-
}
189-
190-
process.on(getCtrlCSignal(), async () => {
191-
const log: Logger = getLogger();
192-
log.info(`Get SIGINT signal!`);
193-
});
194-
195-
process.on(getStopSignal(), async () => {
182+
async function cleanUp(): Promise<void> {
196183
const log: Logger = getLogger();
197184
let hasError: boolean = false;
198185
try {
@@ -206,7 +193,11 @@ process.on(getStopSignal(), async () => {
206193
hasError = true;
207194
log.error(`${err.stack}`);
208195
} finally {
209-
await log.close();
196+
log.close();
210197
process.exit(hasError ? 1 : 0);
211198
}
212-
});
199+
}
200+
201+
process.on('SIGTERM', cleanUp);
202+
process.on('SIGBREAK', cleanUp);
203+
process.on('SIGINT', cleanUp);

0 commit comments

Comments
 (0)