Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
disconnect works when program is done
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamah committed Feb 20, 2020
1 parent 2fb6f9f commit 5ab2a1b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
17 changes: 17 additions & 0 deletions src/common/debugger_communication_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,20 @@ def input_changed(data):
@sio.on("received_state")
def received_state(data):
processing_state_event.set()


# @sio.event
# def disconnect():
# print("I'm disconnected!")


@sio.on("frontend_disconnected")
def frontend_disconnected(data):
print("disconnecting...")
sio.disconnect()


def disconnect_socket():
print("disconnecting here!")
sio.disconnect()

2 changes: 2 additions & 0 deletions src/debug_user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@
for frameIndex in range(2, len(stackTrace) - 1):
errorMessage += "\t" + str(stackTrace[frameIndex])
print(e, errorMessage, file=sys.stderr, flush=True)

debugger_communication_client.disconnect_socket()
21 changes: 11 additions & 10 deletions src/debuggerCommunicationServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class DebuggerCommunicationServer {
private simulatorWebview: WebviewPanel | undefined;
private currentActiveDevice;
private isWaitingResponse = false;
private currentCall :Array<Function>= []
private currentCall: Array<Function> = []

constructor(
webviewPanel: WebviewPanel | undefined,
Expand Down Expand Up @@ -44,17 +44,17 @@ export class DebuggerCommunicationServer {


public emitInputChanged(newState: string): void {
if(this.isWaitingResponse){
if (this.isWaitingResponse) {
console.log('I have added a call to the queue')
this.currentCall.push(()=>{
this.currentCall.push(() => {
console.log("I will send another input for sensor_changed")
this.serverIo.emit("input_changed", newState)
this.isWaitingResponse=true;
this.isWaitingResponse = true;
})

}else{
} else {
this.serverIo.emit("input_changed", newState)
this.isWaitingResponse=true;
this.isWaitingResponse = true;
}
}

Expand All @@ -73,19 +73,20 @@ export class DebuggerCommunicationServer {
this.handleState(data);
this.serverIo.emit("received_state", {})
});
socket.on("receivedState",()=>{
this.isWaitingResponse=false;
if(this.currentCall.length>0){
socket.on("receivedState", () => {
this.isWaitingResponse = false;
if (this.currentCall.length > 0) {
let currentCall = this.currentCall.shift()
console.log("The previous state has been received by the python api")
currentCall()
}

}

);

socket.on("disconnect", () => {
this.serverIo.emit("frontend_disconnected", {})
console.log("Socket disconnected");
if (this.simulatorWebview) {
this.simulatorWebview.webview.postMessage({
Expand Down

0 comments on commit 5ab2a1b

Please sign in to comment.