Skip to content

Commit d9243ee

Browse files
authored
Merge pull request #844 from JohanMabille/continued_event
2 parents 996dd5c + 34ee173 commit d9243ee

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

ipykernel/debugger.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import threading
34

45
import zmq
56
from zmq.utils import jsonapi
@@ -284,7 +285,7 @@ def __init__(self, log, debugpy_stream, event_callback, shell_socket, session):
284285
self.static_debug_handlers[msg_type] = getattr(self, msg_type)
285286

286287
self.breakpoint_list = {}
287-
self.stopped_threads = []
288+
self.stopped_threads = set()
288289

289290
self.debugpy_initialized = False
290291
self._removed_cleanup = {}
@@ -297,12 +298,21 @@ def __init__(self, log, debugpy_stream, event_callback, shell_socket, session):
297298

298299
def _handle_event(self, msg):
299300
if msg['event'] == 'stopped':
300-
self.stopped_threads.append(msg['body']['threadId'])
301+
self.stopped_threads.add(msg['body']['threadId'])
301302
elif msg['event'] == 'continued':
302303
try:
303-
self.stopped_threads.remove(msg['body']['threadId'])
304+
if msg['allThreadsContinued']:
305+
self.stopped_threads = set()
306+
else:
307+
self.stopped_threads.remove(msg['body']['threadId'])
304308
except Exception:
305-
pass
309+
# Workaround for debugpy/pydev not setting the correct threadId
310+
# after a next request. Does not work if a the code executed on
311+
# the shell spawns additional threads
312+
if len(self.stopped_threads) == 1:
313+
self.stopped_threads = set()
314+
else:
315+
raise Exception('threadId from continued event not in stopped threads set')
306316
self.event_callback(msg)
307317

308318
async def _forward_message(self, msg):
@@ -513,7 +523,7 @@ async def debugInfo(self, message):
513523
'tmpFilePrefix': get_tmp_directory() + os.sep,
514524
'tmpFileSuffix': '.py',
515525
'breakpoints': breakpoint_list,
516-
'stoppedThreads': self.stopped_threads,
526+
'stoppedThreads': list(self.stopped_threads),
517527
'richRendering': True,
518528
'exceptionPaths': ['Python Exceptions']
519529
}
@@ -613,7 +623,7 @@ async def process_request(self, message):
613623
if message['command'] == 'disconnect':
614624
self.stop()
615625
self.breakpoint_list = {}
616-
self.stopped_threads = []
626+
self.stopped_threads = set()
617627
self.is_started = False
618628
self.log.info('The debugger has stopped')
619629

0 commit comments

Comments
 (0)