the breakpoint highlighted lines will disappear or jump around between difference debug sessions (it should be noted this issue won't come out for single session breakpoints). For example when debugging multi-process python code, when we only set a breakpoint in main process, but sometimes current breakpoint hightlighted line will disappear and jump to the subprocess debug breakpoint.
from multiprocessing import Process
import threading
import time
class myThread (threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
def run(self):
print_time(self.name, 10, self.counter)
def print_time(threadName, counter, delay):
while counter:
time.sleep(delay)
counter -= 1
def print_func(continent='Asia'):
thread1 = myThread(1, "Thread-1", 1)
thread1.start()
time.sleep(120)
print('The name of continent is : ', continent)
if __name__ == "__main__": # confirms that the code is under main function
names = ['America', 'Europe', 'Africa']
procs = []
proc = Process(target=print_func) # instantiating without any argument
procs.append(proc)
proc.start()
# instantiating process with arguments
for name in names:
proc = Process(target=print_func, args=(name,))
procs.append(proc)
proc.start()
# complete the processes
for proc in procs:
proc.join()
normal:
abnormal:
@tom-shan I assume the same scenario works for you correctly in vscode?
I wanted to confirm if it was a bug with the framework or the python extension itself.
@tom-shan I assume the same scenario works for you correctly in vscode?
I wanted to confirm if it was a bug with the framework or the python extension itself.
yes, I think so, it works much better in vscode, the current breakpoint highlighted line will not disappear.
Actually I have found some problems in theia about the manipulation of "thread" DAP event with "started" or "exited" reason.
In short, when theia receives the "thread" event which is generated by another debug session, theia will change to that session see https://github.com/eclipse-theia/theia/blob/master/packages/debug/src/browser/debug-session.tsx#L102-L108
Here is vscode's implementation of the thread DAP event for reference:
this.rawListeners.push(this.raw.onDidThread(event => {
if (event.body.reason === 'started') {
// debounce to reduce threadsRequest frequency and improve performance
if (!this.fetchThreadsScheduler) {
this.fetchThreadsScheduler = new RunOnceScheduler(() => {
this.fetchThreads();
}, 100);
this.rawListeners.push(this.fetchThreadsScheduler);
}
if (!this.fetchThreadsScheduler.isScheduled()) {
this.fetchThreadsScheduler.schedule();
}
} else if (event.body.reason === 'exited') {
this.model.clearThreads(this.getId(), true, event.body.threadId);
const viewModel = this.debugService.getViewModel();
const focusedThread = viewModel.focusedThread;
if (focusedThread && event.body.threadId === focusedThread.threadId) {
// De-focus the thread in case it was focused
this.debugService.focusStackFrame(undefined, undefined, viewModel.focusedSession, false);
}
}
}));