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

quick fix kill command under windows #3106

Merged
merged 4 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nni/tools/nnictl/command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def check_output_command(file_path, head=None, tail=None):
def kill_command(pid):
"""kill command"""
if sys.platform == 'win32':
psutil.Process(pid).terminate()
process = psutil.Process(pid=pid)
process.send_signal(signal.CTRL_BREAK_EVENT)
else:
cmds = ['kill', str(pid)]
call(cmds)
Expand Down
23 changes: 7 additions & 16 deletions ts/nni_manager/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,7 @@ mkDirP(getLogDir())
console.error(`Failed to create log dir: ${err.stack}`);
});

function getStopSignal(): any {
return 'SIGTERM';
}

function getCtrlCSignal(): any {
return 'SIGINT';
}

process.on(getCtrlCSignal(), async () => {
const log: Logger = getLogger();
log.info(`Get SIGINT signal!`);
});

process.on(getStopSignal(), async () => {
async function cleanUp(): Promise<void> {
const log: Logger = getLogger();
let hasError: boolean = false;
try {
Expand All @@ -201,7 +188,11 @@ process.on(getStopSignal(), async () => {
hasError = true;
log.error(`${err.stack}`);
} finally {
await log.close();
log.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove await?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger.close() is a sync function

process.exit(hasError ? 1 : 0);
}
});
}

process.on('SIGTERM', cleanUp);
process.on('SIGBREAK', cleanUp);
process.on('SIGINT', cleanUp);