9393 PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING ,
9494 PYDEVD_IPYTHON_CONTEXT ,
9595 PYDEVD_USE_SYS_MONITORING ,
96+ IS_PY314_OR_GREATER ,
9697)
9798from _pydevd_bundle .pydevd_defaults import PydevdCustomization # Note: import alias used on pydev_monkey.
9899from _pydevd_bundle .pydevd_custom_frames import CustomFramesContainer , custom_frames_container_init
@@ -724,6 +725,8 @@ def __init__(self, set_as_global=True):
724725
725726 self ._local_thread_trace_func = threading .local ()
726727
728+ self ._client_socket = None
729+
727730 self ._server_socket_ready_event = ThreadingEvent ()
728731 self ._server_socket_name = None
729732
@@ -1287,6 +1290,16 @@ def in_project_scope(self, frame, absolute_filename=None):
12871290 if file_type == self .PYDEV_FILE :
12881291 cache [cache_key ] = False
12891292
1293+ elif IS_PY314_OR_GREATER and frame .f_code .co_name == "__annotate__" :
1294+ # Special handling for __annotate__ functions (PEP 649 in Python 3.14+).
1295+ # These are compiler-generated functions that can raise NotImplementedError
1296+ # when called with unsupported format arguments by inspect.call_annotate_function.
1297+ # They should be treated as library code to avoid false positives in exception handling.
1298+ # Note: PEP 649 reserves the __annotate__ name for compiler-generated functions,
1299+ # so user-defined functions with this name are discouraged and will also be treated
1300+ # as library code to maintain consistency with the language design.
1301+ cache [cache_key ] = False
1302+
12901303 elif absolute_filename == "<string>" :
12911304 # Special handling for '<string>'
12921305 if file_type == self .LIB_FILE :
@@ -1501,6 +1514,7 @@ def initialize_network(self, sock, terminate_on_socket_close=True):
15011514 def connect (self , host , port ):
15021515 if host :
15031516 s = start_client (host , port )
1517+ self ._client_socket = s
15041518 else :
15051519 s = start_server (port )
15061520
@@ -2547,6 +2561,10 @@ def dispose_and_kill_all_pydevd_threads(self, wait=True, timeout=0.5):
25472561 except :
25482562 pass
25492563 finally :
2564+ if self ._client_socket :
2565+ self ._client_socket .close ()
2566+ self ._client_socket = None
2567+
25502568 pydev_log .debug ("PyDB.dispose_and_kill_all_pydevd_threads: finished" )
25512569
25522570 def prepare_to_run (self ):
@@ -2935,6 +2953,7 @@ def settrace(
29352953 client_access_token = None ,
29362954 notify_stdin = True ,
29372955 protocol = None ,
2956+ ppid = 0 ,
29382957 ** kwargs ,
29392958):
29402959 """Sets the tracing function with the pydev debug function and initializes needed facilities.
@@ -2994,6 +3013,11 @@ def settrace(
29943013 When using in Eclipse the protocol should not be passed, but when used in VSCode
29953014 or some other IDE/editor that accepts the Debug Adapter Protocol then 'dap' should
29963015 be passed.
3016+
3017+ :param ppid:
3018+ Override the parent process id (PPID) for the current debugging session. This PPID is
3019+ reported to the debug client (IDE) and can be used to act like a child process of an
3020+ existing debugged process without being a child process.
29973021 """
29983022 if protocol and protocol .lower () == "dap" :
29993023 pydevd_defaults .PydevdCustomization .DEFAULT_PROTOCOL = pydevd_constants .HTTP_JSON_PROTOCOL
@@ -3022,6 +3046,7 @@ def settrace(
30223046 client_access_token ,
30233047 __setup_holder__ = __setup_holder__ ,
30243048 notify_stdin = notify_stdin ,
3049+ ppid = ppid ,
30253050 )
30263051
30273052
@@ -3045,6 +3070,7 @@ def _locked_settrace(
30453070 client_access_token ,
30463071 __setup_holder__ ,
30473072 notify_stdin ,
3073+ ppid ,
30483074):
30493075 if patch_multiprocessing :
30503076 try :
@@ -3076,6 +3102,7 @@ def _locked_settrace(
30763102 "port" : int (port ),
30773103 "multiprocess" : patch_multiprocessing ,
30783104 "skip-notify-stdin" : not notify_stdin ,
3105+ pydevd_constants .ARGUMENT_PPID : ppid ,
30793106 }
30803107 SetupHolder .setup = setup
30813108
0 commit comments