Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Dec 18, 2023
1 parent 274fd81 commit ca4cfee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions _pydev_runfiles/pydev_runfiles_xml_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def notifyTest(self, *args):
class ServerComm(threading.Thread):

def __init__(self, notifications_queue, port, daemon=False):
threading.Thread.__init__(self)
self.setDaemon(daemon) # If False, wait for all the notifications to be passed before exiting!
# If daemon is False, wait for all the notifications to be passed before exiting!
threading.Thread.__init__(self, daemon=daemon)
self.finished = False
self.notifications_queue = notifications_queue

Expand Down
17 changes: 14 additions & 3 deletions _pydevd_bundle/pydevd_additional_thread_info_regular.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def __str__(self):


_set_additional_thread_info_lock = ForkSafeLock()
_next_additional_info = [PyDBAdditionalThreadInfo()]


def set_additional_thread_info(thread):
Expand All @@ -145,9 +146,19 @@ def set_additional_thread_info(thread):
with _set_additional_thread_info_lock:
# If it's not there, set it within a lock to avoid any racing
# conditions.
additional_info = getattr(thread, 'additional_info', None)
try:
additional_info = thread.additional_info
except:
additional_info = None

if additional_info is None:
additional_info = PyDBAdditionalThreadInfo()
thread.additional_info = additional_info
# Note: don't call PyDBAdditionalThreadInfo constructor at this
# point as it can piggy-back into the debugger which could
# get here again, rather get the global ref which was pre-created
# and add a new entry only after we set thread.additional_info.
additional_info = _next_additional_info[0]
thread.additional_info = additional_info
del _next_additional_info[:]
_next_additional_info.append(PyDBAdditionalThreadInfo())

return additional_info
17 changes: 6 additions & 11 deletions _pydevd_sys_monitoring/pydevd_sys_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from _pydev_bundle import pydev_log
from _pydevd_bundle import pydevd_dont_trace
from _pydevd_bundle.pydevd_additional_thread_info import _set_additional_thread_info_lock, set_additional_thread_info, PyDBAdditionalThreadInfo
from _pydevd_bundle.pydevd_additional_thread_info import set_additional_thread_info, PyDBAdditionalThreadInfo
from _pydevd_bundle.pydevd_constants import (GlobalDebuggerHolder, ForkSafeLock,
PYDEVD_IPYTHON_CONTEXT, EXCEPTION_TYPE_USER_UNHANDLED, RETURN_VALUES_DICT,
PYTHON_SUSPEND)
Expand Down Expand Up @@ -91,12 +91,13 @@ def _get_bootstrap_frame(depth) -> Tuple[Optional[FrameType], bool]:
while f_bootstrap is not None:
filename = f_bootstrap.f_code.co_filename
name = splitext(basename(filename))[0]

if name == 'threading':
if f_bootstrap.f_code.co_name in ('__bootstrap', '_bootstrap'):
# We need __bootstrap_inner, not __bootstrap.
return None, False

elif f_bootstrap.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'):
elif f_bootstrap.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner', 'is_alive'):
# Note: be careful not to use threading.current_thread to avoid creating a dummy thread.
is_bootstrap_frame_internal = True
break
Expand Down Expand Up @@ -203,7 +204,7 @@ def _create_thread_info(depth):

if is_bootstrap_frame_internal:
t = None
if f_bootstrap_frame.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'):
if f_bootstrap_frame.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner', 'is_alive'):
# Note: be careful not to use threading.current_thread to avoid creating a dummy thread.
t = f_bootstrap_frame.f_locals.get('self')
if not isinstance(t, threading.Thread):
Expand All @@ -216,7 +217,7 @@ def _create_thread_info(depth):
t = None

else:
# This means that the first frame is not in threading nor in pydev.
# This means that the first frame is not in threading nor in pydevd.
# In practice this means it's some unmanaged thread, so, creating
# a dummy thread is ok in this use-case.
t = threading.current_thread()
Expand All @@ -239,13 +240,7 @@ def _create_thread_info(depth):
if additional_info is None:
raise AttributeError()
except:
with _set_additional_thread_info_lock:
# If it's not there, set it within a lock to avoid any racing
# conditions.
additional_info = getattr(t, 'additional_info', None)
if additional_info is None:
additional_info = PyDBAdditionalThreadInfo()
t.additional_info = additional_info
additional_info = set_additional_thread_info(t)
return ThreadInfo(t, True, additional_info)


Expand Down
2 changes: 1 addition & 1 deletion tests_python/debugger_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class IgnoreFailureError(RuntimeError):
#=======================================================================================================================
class ReaderThread(threading.Thread):

MESSAGES_TIMEOUT = 15
MESSAGES_TIMEOUT = 10

def __init__(self, sock):
threading.Thread.__init__(self)
Expand Down

0 comments on commit ca4cfee

Please sign in to comment.