Skip to content

Commit 6eabde4

Browse files
authored
✨ Terminate python process when ending debug session (#821)
Fixes #754 This is change is specific to the experimental debugger Moved the static run method out of the class, as a standalone function named startDebugger Added logToFile into package.json (publish this setting) Added logging of unhandled exceptions in debugger process (for diagnostics) Terminate python process when ending debugger
1 parent d44386e commit 6eabde4

6 files changed

Lines changed: 219 additions & 118 deletions

File tree

package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,11 @@
674674
"type": "string",
675675
"description": "IP address of the of the local debug server (default is localhost).",
676676
"default": "localhost"
677+
},
678+
"logToFile": {
679+
"type": "boolean",
680+
"description": "Enable logging of debugger events to a log file.",
681+
"default": false
677682
}
678683
}
679684
},
@@ -707,6 +712,11 @@
707712
"type": "string",
708713
"description": "Secret used to authenticate for remote debugging.",
709714
"default": ""
715+
},
716+
"logToFile": {
717+
"type": "boolean",
718+
"description": "Enable logging of debugger events to a log file.",
719+
"default": false
710720
}
711721
}
712722
}
@@ -1021,6 +1031,11 @@
10211031
"type": "string",
10221032
"description": "IP address of the of the local debug server (default is localhost).",
10231033
"default": "localhost"
1034+
},
1035+
"logToFile": {
1036+
"type": "boolean",
1037+
"description": "Enable logging of debugger events to a log file.",
1038+
"default": false
10241039
}
10251040
}
10261041
}
@@ -1761,6 +1776,7 @@
17611776
"md5": "^2.2.1",
17621777
"minimatch": "^3.0.3",
17631778
"named-js-regexp": "^1.3.1",
1779+
"once": "^1.4.0",
17641780
"opn": "^5.1.0",
17651781
"pidusage": "^1.2.0",
17661782
"reflect-metadata": "^0.1.12",
@@ -1795,6 +1811,7 @@
17951811
"@types/md5": "^2.1.32",
17961812
"@types/mocha": "^2.2.43",
17971813
"@types/node": "^6.0.40",
1814+
"@types/once": "^1.4.0",
17981815
"@types/semver": "^5.4.0",
17991816
"@types/shortid": "0.0.29",
18001817
"@types/sinon": "^2.3.2",
@@ -1820,6 +1837,7 @@
18201837
"gulp-typescript": "^3.2.2",
18211838
"gulp-watch": "^4.3.11",
18221839
"husky": "^0.14.3",
1840+
"is-running": "^2.1.0",
18231841
"istanbul": "^0.4.5",
18241842
"mocha": "^2.3.3",
18251843
"relative": "^3.0.2",
@@ -1841,4 +1859,4 @@
18411859
"publisherDisplayName": "Microsoft",
18421860
"publisherId": "998b010b-e2af-44a5-a6cd-0b5fd3b9b6f8"
18431861
}
1844-
}
1862+
}

src/client/debugger/Common/Contracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
6464
console?: 'none' | 'integratedTerminal' | 'externalTerminal';
6565
port?: number;
6666
host?: string;
67-
diagnosticLogging?: boolean;
6867
logToFile?: boolean;
6968
}
7069

@@ -75,6 +74,7 @@ export interface AttachRequestArguments extends DebugProtocol.AttachRequestArgum
7574
port?: number;
7675
host?: string;
7776
secret?: string;
77+
logToFile?: boolean;
7878
}
7979

8080
export interface IDebugServer {

src/client/debugger/Main.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ export class PythonDebugger extends LoggingDebugSession {
211211
}
212212
@capturePerformanceTelemetry('launch')
213213
protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
214-
if (args.diagnosticLogging === true) {
215-
logger.setup(LogLevel.Verbose, args.logToFile === true);
214+
if (args.logToFile === true) {
215+
logger.setup(LogLevel.Verbose, true);
216216
}
217217
// Some versions may still exist with incorrect launch.json values
218218
const setting = '${config.python.pythonPath}';
@@ -290,8 +290,8 @@ export class PythonDebugger extends LoggingDebugSession {
290290
});
291291
}
292292
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments) {
293-
if ((args as any).diagnosticLogging === true) {
294-
logger.setup(LogLevel.Verbose, (args as any).logToFile === true);
293+
if (args.logToFile === true) {
294+
logger.setup(LogLevel.Verbose, true);
295295
}
296296
this.sendEvent(new TelemetryEvent(DEBUGGER, { trigger: 'attach' }));
297297

@@ -735,4 +735,14 @@ export class PythonDebugger extends LoggingDebugSession {
735735
}
736736
}
737737

738+
process.on('uncaughtException', (err: Error) => {
739+
logger.error(`Uncaught Exception: ${err && err.message ? err.message : ''}`);
740+
logger.error(err && err.name ? err.name : '');
741+
logger.error(err && err.stack ? err.stack : '');
742+
// Catch all, incase we have string exceptions being raised.
743+
logger.error(err ? err.toString() : '');
744+
// Wait for 1 second before we die, we need to ensure errors are written to the log file.
745+
setTimeout(() => process.exit(-1), 1000);
746+
});
747+
738748
LoggingDebugSession.run(PythonDebugger);

0 commit comments

Comments
 (0)