mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix multiprocessing debug with breakpoints in both main and child processes (PY-17092)
When the new process is created, the main thread in the new process already has the attribute '__pydevd_id__', so the new thread doesn't get new id with its process number and the debugger loses access to both threads. Therefore we should update thread_id for every main thread in the new process.
This commit is contained in:
@@ -556,14 +556,17 @@ class PyDB:
|
||||
self._lock_running_thread_ids.acquire()
|
||||
try:
|
||||
for t in all_threads:
|
||||
thread_id = GetThreadId(t)
|
||||
|
||||
if getattr(t, 'is_pydev_daemon_thread', False):
|
||||
pass # I.e.: skip the DummyThreads created from pydev daemon threads
|
||||
elif isinstance(t, PyDBDaemonThread):
|
||||
pydev_log.error_once('Error in debugger: Found PyDBDaemonThread not marked with is_pydev_daemon_thread=True.\n')
|
||||
|
||||
elif isThreadAlive(t):
|
||||
if not self._running_thread_ids:
|
||||
thread_id = GetThreadId(t, True)
|
||||
curr_thread_id = GetThreadId(threadingCurrentThread())
|
||||
else:
|
||||
thread_id = GetThreadId(t)
|
||||
program_threads_alive[thread_id] = t
|
||||
|
||||
if not DictContains(self._running_thread_ids, thread_id):
|
||||
|
||||
@@ -195,29 +195,38 @@ class NextId:
|
||||
|
||||
_nextThreadId = NextId()
|
||||
|
||||
|
||||
#=======================================================================================================================
|
||||
# GetPid
|
||||
#=======================================================================================================================
|
||||
def GetPid():
|
||||
try:
|
||||
return os.getpid()
|
||||
except AttributeError:
|
||||
try:
|
||||
#Jython does not have it!
|
||||
import java.lang.management.ManagementFactory #@UnresolvedImport -- just for jython
|
||||
pid = java.lang.management.ManagementFactory.getRuntimeMXBean().getName()
|
||||
return pid.replace('@', '_')
|
||||
except:
|
||||
#ok, no pid available (will be unable to debug multiple processes)
|
||||
return '000001'
|
||||
|
||||
|
||||
#=======================================================================================================================
|
||||
# GetThreadId
|
||||
#=======================================================================================================================
|
||||
def GetThreadId(thread):
|
||||
def GetThreadId(thread, update_pydevd_id=False):
|
||||
try:
|
||||
if update_pydevd_id:
|
||||
del thread.__pydevd_id__
|
||||
return thread.__pydevd_id__
|
||||
except AttributeError:
|
||||
_nextThreadIdLock.acquire()
|
||||
try:
|
||||
#We do a new check with the lock in place just to be sure that nothing changed
|
||||
if not hasattr(thread, '__pydevd_id__'):
|
||||
try:
|
||||
pid = os.getpid()
|
||||
except AttributeError:
|
||||
try:
|
||||
#Jython does not have it!
|
||||
import java.lang.management.ManagementFactory #@UnresolvedImport -- just for jython
|
||||
pid = java.lang.management.ManagementFactory.getRuntimeMXBean().getName()
|
||||
pid = pid.replace('@', '_')
|
||||
except:
|
||||
#ok, no pid available (will be unable to debug multiple processes)
|
||||
pid = '000001'
|
||||
|
||||
pid = GetPid()
|
||||
thread.__pydevd_id__ = 'pid%s_seq%s' % (pid, _nextThreadId())
|
||||
finally:
|
||||
_nextThreadIdLock.release()
|
||||
|
||||
Reference in New Issue
Block a user