1
1
import os
2
2
import re
3
+ import threading
3
4
4
5
import zmq
5
6
from zmq .utils import jsonapi
@@ -284,7 +285,7 @@ def __init__(self, log, debugpy_stream, event_callback, shell_socket, session):
284
285
self .static_debug_handlers [msg_type ] = getattr (self , msg_type )
285
286
286
287
self .breakpoint_list = {}
287
- self .stopped_threads = []
288
+ self .stopped_threads = set ()
288
289
289
290
self .debugpy_initialized = False
290
291
self ._removed_cleanup = {}
@@ -297,12 +298,21 @@ def __init__(self, log, debugpy_stream, event_callback, shell_socket, session):
297
298
298
299
def _handle_event (self , msg ):
299
300
if msg ['event' ] == 'stopped' :
300
- self .stopped_threads .append (msg ['body' ]['threadId' ])
301
+ self .stopped_threads .add (msg ['body' ]['threadId' ])
301
302
elif msg ['event' ] == 'continued' :
302
303
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' ])
304
308
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' )
306
316
self .event_callback (msg )
307
317
308
318
async def _forward_message (self , msg ):
@@ -513,7 +523,7 @@ async def debugInfo(self, message):
513
523
'tmpFilePrefix' : get_tmp_directory () + os .sep ,
514
524
'tmpFileSuffix' : '.py' ,
515
525
'breakpoints' : breakpoint_list ,
516
- 'stoppedThreads' : self .stopped_threads ,
526
+ 'stoppedThreads' : list ( self .stopped_threads ) ,
517
527
'richRendering' : True ,
518
528
'exceptionPaths' : ['Python Exceptions' ]
519
529
}
@@ -613,7 +623,7 @@ async def process_request(self, message):
613
623
if message ['command' ] == 'disconnect' :
614
624
self .stop ()
615
625
self .breakpoint_list = {}
616
- self .stopped_threads = []
626
+ self .stopped_threads = set ()
617
627
self .is_started = False
618
628
self .log .info ('The debugger has stopped' )
619
629
0 commit comments