Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Nov 19, 2023
1 parent 3ad6c83 commit 2cc2b71
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 71 deletions.
4 changes: 2 additions & 2 deletions _pydev_bundle/pydev_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from _pydev_bundle._pydev_saved_modules import threading
from _pydevd_bundle.pydevd_constants import get_global_debugger, IS_WINDOWS, IS_JYTHON, get_current_thread_id, \
sorted_dict_repr, set_global_debugger, DebugInfoHolder, USE_SYS_MONITORING
sorted_dict_repr, set_global_debugger, DebugInfoHolder, PYDEVD_USE_SYS_MONITORING
from _pydev_bundle import pydev_log
from contextlib import contextmanager
from _pydevd_bundle import pydevd_constants, pydevd_defaults
Expand Down Expand Up @@ -234,7 +234,7 @@ def _on_forked_process(setup_tracing=True):

def _on_set_trace_for_new_thread(global_debugger):
if global_debugger is not None:
if not USE_SYS_MONITORING:
if not PYDEVD_USE_SYS_MONITORING:
global_debugger.enable_tracing()


Expand Down
4 changes: 2 additions & 2 deletions _pydevd_bundle/pydevd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CMD_STEP_INTO_MY_CODE, CMD_STOP_ON_START, CMD_SMART_STEP_INTO)
from _pydevd_bundle.pydevd_constants import (get_current_thread_id, set_protocol, get_protocol,
HTTP_JSON_PROTOCOL, JSON_PROTOCOL, DebugInfoHolder, IS_WINDOWS,
USE_SYS_MONITORING)
PYDEVD_USE_SYS_MONITORING)
from _pydevd_bundle.pydevd_net_command_factory_json import NetCommandFactoryJson
from _pydevd_bundle.pydevd_net_command_factory_xml import NetCommandFactory
import pydevd_file_utils
Expand Down Expand Up @@ -926,7 +926,7 @@ def stop_on_entry(self):
info = set_additional_thread_info(main_thread)
info.pydev_original_step_cmd = CMD_STOP_ON_START
info.pydev_step_cmd = CMD_STEP_INTO_MY_CODE
if USE_SYS_MONITORING:
if PYDEVD_USE_SYS_MONITORING:
pydevd_sys_monitoring.update_monitor_events(suspend_requested=True)
pydevd_sys_monitoring.restart_events()

Expand Down
17 changes: 13 additions & 4 deletions _pydevd_bundle/pydevd_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ def _current_frames():
IS_PY311_OR_GREATER = sys.version_info >= (3, 11)
IS_PY312_OR_GREATER = sys.version_info >= (3, 12)

USE_SYS_MONITORING = IS_PY312_OR_GREATER and hasattr(sys, 'monitoring')
# USE_SYS_MONITORING = False

# Not currently supported in Python 3.12.
SUPPORT_ATTACH_TO_PID = not IS_PY312_OR_GREATER

Expand All @@ -196,6 +193,18 @@ def version_str(v):
ENV_TRUE_LOWER_VALUES = ('yes', 'true', '1')
ENV_FALSE_LOWER_VALUES = ('no', 'false', '0')

PYDEVD_USE_SYS_MONITORING = IS_PY312_OR_GREATER and hasattr(sys, 'monitoring')
if PYDEVD_USE_SYS_MONITORING: # Default gotten, let's see if it was somehow customize by the user.
_use_sys_monitoring_env_var = os.getenv('PYDEVD_USE_SYS_MONITORING', '').lower()
if _use_sys_monitoring_env_var:
# Check if the user specified something.
if _use_sys_monitoring_env_var in ENV_FALSE_LOWER_VALUES:
PYDEVD_USE_SYS_MONITORING = False
elif _use_sys_monitoring_env_var in ENV_TRUE_LOWER_VALUES:
PYDEVD_USE_SYS_MONITORING = True
else:
raise RuntimeError('Unrecognized value for PYDEVD_USE_SYS_MONITORING: %s' % (_use_sys_monitoring_env_var,))


def is_true_in_env(env_key):
if isinstance(env_key, tuple):
Expand Down Expand Up @@ -513,7 +522,7 @@ def iter_chars(b):
return iter(b)


if IS_JYTHON or USE_SYS_MONITORING:
if IS_JYTHON or PYDEVD_USE_SYS_MONITORING:

def NO_FTRACE(frame, event, arg):
return None
Expand Down
28 changes: 14 additions & 14 deletions _pydevd_bundle/pydevd_cython.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions _pydevd_bundle/pydevd_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ from _pydev_bundle import pydev_log
from _pydevd_bundle import pydevd_dont_trace
from _pydevd_bundle.pydevd_constants import (RETURN_VALUES_DICT, NO_FTRACE,
EXCEPTION_TYPE_HANDLED, EXCEPTION_TYPE_USER_UNHANDLED, PYDEVD_IPYTHON_CONTEXT,
USE_SYS_MONITORING)
PYDEVD_USE_SYS_MONITORING)
from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace
from _pydevd_bundle.pydevd_utils import get_clsname_for_code
from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame
Expand Down Expand Up @@ -293,7 +293,7 @@ cdef class PyDBFrame:
# should_skip = -1 # Default value in class (put in instance on set).
# exc_info = () # Default value in class (put in instance on set).
#
# if USE_SYS_MONITORING:
# if PYDEVD_USE_SYS_MONITORING:
#
# def __init__(self, *args, **kwargs):
# raise RuntimeError("Not expected to be used in sys.monitoring.")
Expand Down Expand Up @@ -1404,7 +1404,7 @@ from _pydev_bundle.pydev_is_thread_alive import is_thread_alive
from _pydev_bundle.pydev_log import exception as pydev_log_exception
from _pydev_bundle._pydev_saved_modules import threading
from _pydevd_bundle.pydevd_constants import (get_current_thread_id, NO_FTRACE,
USE_CUSTOM_SYS_CURRENT_FRAMES_MAP, ForkSafeLock, USE_SYS_MONITORING)
USE_CUSTOM_SYS_CURRENT_FRAMES_MAP, ForkSafeLock, PYDEVD_USE_SYS_MONITORING)
from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER

# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated)
Expand Down Expand Up @@ -1885,7 +1885,7 @@ if USE_CUSTOM_SYS_CURRENT_FRAMES_MAP:

ThreadTracer.__call__ = __call__

if USE_SYS_MONITORING:
if PYDEVD_USE_SYS_MONITORING:

def fix_top_level_trace_and_get_trace_func(*args, **kwargs):
raise RuntimeError('Not used in sys.monitoring mode.')
4 changes: 2 additions & 2 deletions _pydevd_bundle/pydevd_daemon_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from _pydevd_bundle.pydevd_utils import notify_about_gevent_if_needed
import weakref
from _pydevd_bundle.pydevd_constants import IS_JYTHON, IS_IRONPYTHON, \
PYDEVD_APPLY_PATCHING_TO_HIDE_PYDEVD_THREADS, USE_SYS_MONITORING
PYDEVD_APPLY_PATCHING_TO_HIDE_PYDEVD_THREADS, PYDEVD_USE_SYS_MONITORING
from _pydev_bundle.pydev_log import exception as pydev_log_exception
import sys
from _pydev_bundle import pydev_log
Expand Down Expand Up @@ -68,7 +68,7 @@ def do_kill_pydev_thread(self):

def _stop_trace(self):
if self.pydev_do_not_trace:
if USE_SYS_MONITORING:
if PYDEVD_USE_SYS_MONITORING:
pydevd_sys_monitoring.stop_monitoring(all_threads=False)
return
pydevd_tracing.SetTrace(None) # no debugging on this thread
Expand Down
4 changes: 2 additions & 2 deletions _pydevd_bundle/pydevd_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from _pydevd_bundle import pydevd_dont_trace
from _pydevd_bundle.pydevd_constants import (RETURN_VALUES_DICT, NO_FTRACE,
EXCEPTION_TYPE_HANDLED, EXCEPTION_TYPE_USER_UNHANDLED, PYDEVD_IPYTHON_CONTEXT,
USE_SYS_MONITORING)
PYDEVD_USE_SYS_MONITORING)
from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace
from _pydevd_bundle.pydevd_utils import get_clsname_for_code
from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame
Expand Down Expand Up @@ -146,7 +146,7 @@ class PyDBFrame:
should_skip = -1 # Default value in class (put in instance on set).
exc_info = () # Default value in class (put in instance on set).

if USE_SYS_MONITORING:
if PYDEVD_USE_SYS_MONITORING:

def __init__(self, *args, **kwargs):
raise RuntimeError("Not expected to be used in sys.monitoring.")
Expand Down
6 changes: 3 additions & 3 deletions _pydevd_bundle/pydevd_thread_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from _pydevd_bundle.pydevd_additional_thread_info import set_additional_thread_info
from _pydevd_bundle.pydevd_comm_constants import CMD_STEP_INTO, CMD_THREAD_SUSPEND
from _pydevd_bundle.pydevd_constants import PYTHON_SUSPEND, STATE_SUSPEND, get_thread_id, STATE_RUN, \
USE_SYS_MONITORING
PYDEVD_USE_SYS_MONITORING
from _pydev_bundle._pydev_saved_modules import threading
from _pydev_bundle import pydev_log
import sys
Expand Down Expand Up @@ -80,7 +80,7 @@ def suspend_all_threads(py_db, except_thread):
Suspend all except the one passed as a parameter.
:param except_thread:
'''
if USE_SYS_MONITORING:
if PYDEVD_USE_SYS_MONITORING:
pydevd_sys_monitoring.update_monitor_events(suspend_requested=True)

pydev_log.info('Suspending all threads except: %s', except_thread)
Expand All @@ -101,6 +101,6 @@ def suspend_all_threads(py_db, except_thread):
finally:
frame = None

if USE_SYS_MONITORING:
if PYDEVD_USE_SYS_MONITORING:
# After suspending the frames we need the monitoring to be reset.
pydevd_sys_monitoring.restart_events()
4 changes: 2 additions & 2 deletions _pydevd_bundle/pydevd_trace_dispatch_regular.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from _pydev_bundle.pydev_log import exception as pydev_log_exception
from _pydev_bundle._pydev_saved_modules import threading
from _pydevd_bundle.pydevd_constants import (get_current_thread_id, NO_FTRACE,
USE_CUSTOM_SYS_CURRENT_FRAMES_MAP, ForkSafeLock, USE_SYS_MONITORING)
USE_CUSTOM_SYS_CURRENT_FRAMES_MAP, ForkSafeLock, PYDEVD_USE_SYS_MONITORING)
from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER

# IFDEF CYTHON
Expand Down Expand Up @@ -489,7 +489,7 @@ def __call__(self, frame, event, arg):

ThreadTracer.__call__ = __call__

if USE_SYS_MONITORING:
if PYDEVD_USE_SYS_MONITORING:

def fix_top_level_trace_and_get_trace_func(*args, **kwargs):
raise RuntimeError('Not used in sys.monitoring mode.')
Loading

0 comments on commit 2cc2b71

Please sign in to comment.