Skip to content

Commit 183bfd2

Browse files
committed
Added ability to pause the program
1 parent 8251270 commit 183bfd2

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/client/debugger/vs/PythonProcess.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class PythonProcess extends EventEmitter implements IPythonProcess {
7474
this.callbackHandler.on("detach", () => this.emit("detach"));
7575
this.callbackHandler.on("last", () => this.emit("last"));
7676
this.callbackHandler.on("moduleLoaded", arg=> this.emit("moduleLoaded", arg));
77+
this.callbackHandler.on("asyncBreakCompleted", arg=> this.emit("asyncBreakCompleted", arg));
7778
this.callbackHandler.on("threadCreated", arg=> this.emit("threadCreated", arg));
7879
this.callbackHandler.on("threadExited", arg=> this.emit("threadExited", arg));
7980
this.callbackHandler.on("stepCompleted", arg=> this.onPythonStepCompleted(arg));
@@ -250,7 +251,9 @@ export class PythonProcess extends EventEmitter implements IPythonProcess {
250251
public SendClearStepping(threadId: number) {
251252

252253
}
253-
254+
public Break() {
255+
this.stream.Write(Commands.BreakAllCommandBytes);
256+
}
254257
public ExecuteText(text: string, reprKind: PythonEvaluationResultReprKind, stackFrame: IPythonStackFrame): Promise<IPythonEvaluationResult> {
255258
return new Promise<IPythonEvaluationResult>((resolve, reject) => {
256259
var executeId = this._idDispenser.Allocate();

src/client/debugger/vs/PythonProcessCallbackHandler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class PythonProcessCallbackHandler extends EventEmitter {
4545
case "EXCP": this.HandleException(); break;
4646
case "EXCR": this.HandleExecutionResult(); break;
4747
case "EXCE": this.HandleExecutionException(); break;
48+
case "ASBR": this.HandleAsyncBreak(); break;
4849
default: {
4950
console.error("Uhandled command = " + cmd);
5051
this.emit("error", `Unhandled command '${cmd}'`);
@@ -152,6 +153,17 @@ export class PythonProcessCallbackHandler extends EventEmitter {
152153
}
153154
this.emit("stepCompleted", pyThread);
154155
}
156+
private HandleAsyncBreak() {
157+
var threadId = this.stream.ReadInt64();
158+
if (this.stream.HasInsufficientDataForReading) {
159+
return;
160+
}
161+
var pyThread: IPythonThread;
162+
if (this.process.Threads.has(threadId)) {
163+
pyThread = this.process.Threads.get(threadId);
164+
}
165+
this.emit("asyncBreakCompleted", pyThread);
166+
}
155167
private HandleBreakPointFailed() {
156168
var id = this.stream.ReadInt32();
157169
if (this.stream.HasInsufficientDataForReading) {

src/client/debugger/vs/VSDebugger.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class PythonDebugSession extends DebugSession {
149149
this.pythonProcess.on("breakpointHit", (pyThread, breakpointId) => this.onBreakpointHit(pyThread, breakpointId));
150150
this.pythonProcess.on("detach", () => this.onDetachDebugger());
151151
this.pythonProcess.on("error", ex => this.sendEvent(new OutputEvent(ex, "stderr")));
152+
this.pythonProcess.on("asyncBreakCompleted", arg=> this.onPythonProcessPaused(arg));
152153
}
153154
private onDetachDebugger() {
154155
this.stopDebugServer();
@@ -166,6 +167,9 @@ class PythonDebugSession extends DebugSession {
166167
private onPythonThreadExited(pyThread: IPythonThread) {
167168
this.sendEvent(new ThreadEvent("exited", pyThread.Id));
168169
}
170+
private onPythonProcessPaused(pyThread: IPythonThread) {
171+
this.sendEvent(new StoppedEvent("pause", pyThread.Id));
172+
}
169173
private onPythonModuleLoaded(module: IPythonModule) {
170174
}
171175
private onPythonProcessLoaded(pyThread: IPythonThread) {
@@ -490,8 +494,8 @@ class PythonDebugSession extends DebugSession {
490494
}
491495

492496
protected pauseRequest(response: DebugProtocol.PauseResponse): void {
493-
console.error('Not yet implemented: pauseRequest');
494-
this.sendErrorResponse(response, 2000, "Pause is not yet supported");
497+
this.pythonProcess.Break();
498+
this.sendResponse(response);
495499
}
496500

497501
protected setExceptionBreakPointsRequest(response: DebugProtocol.SetExceptionBreakpointsResponse, args: DebugProtocol.SetExceptionBreakpointsArguments): void {

0 commit comments

Comments
 (0)