Skip to content

Commit 8380a65

Browse files
committed
Lock for thread suspension, code-formatting.
1 parent 29500d6 commit 8380a65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+182
-195
lines changed

_pydev_bundle/_pydev_calltip_util.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
License: Apache 2.0
33
Author: Yuli Fitterman
44
"""
5+
56
import types
67

78
from _pydevd_bundle.pydevd_constants import IS_JYTHON

_pydev_bundle/fsnotify/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def start_watching(): # Called from thread
3737
3838
Note: changes are only reported for files (added/modified/deleted), not directories.
3939
"""
40+
4041
import sys
4142
from os.path import basename
4243
from _pydev_bundle import pydev_log, _pydev_saved_modules

_pydev_bundle/pydev_ipython_console_011.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# eg: Completing a magic when user typed it without the leading % causes the % to be inserted
1111
# to the left of what should be the first colon.
1212
"""Interface to TerminalInteractiveShell for PyDev Interactive Console frontend
13-
for IPython 0.11 to 1.0+.
13+
for IPython 0.11 to 1.0+.
1414
"""
1515

1616
from __future__ import print_function

_pydevd_bundle/pydevd_additional_thread_info_regular.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _get_related_thread(self):
140140
return None
141141

142142
if thread._ident is None: # Can this happen?
143-
pydev_log.critical("thread._ident is None in _get_related_thread!")
143+
pydev_log.critical("thread._ident is None in _get_related_thread! - thread: %s", thread)
144144
return None
145145

146146
if threading._active.get(thread._ident) is not thread:

_pydevd_bundle/pydevd_comm.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" pydevd - a debugging daemon
1+
"""pydevd - a debugging daemon
22
This is the daemon you launch for python remote debugging.
33
44
Protocol:
@@ -1528,13 +1528,14 @@ def build_exception_info_response(dbg, thread_id, thread, request_seq, set_addit
15281528
if line_col_info.end_lineno is not None and lineno < line_col_info.end_lineno:
15291529
line_text = "\n".join(linecache.getlines(filename_in_utf8)[lineno : line_col_info.end_lineno + 1])
15301530
frame_summary = traceback.FrameSummary(
1531-
filename_in_utf8,
1532-
lineno,
1533-
method_name,
1534-
line=line_text,
1535-
end_lineno=line_col_info.end_lineno,
1536-
colno=line_col_info.colno,
1537-
end_colno=line_col_info.end_colno)
1531+
filename_in_utf8,
1532+
lineno,
1533+
method_name,
1534+
line=line_text,
1535+
end_lineno=line_col_info.end_lineno,
1536+
colno=line_col_info.colno,
1537+
end_colno=line_col_info.end_colno,
1538+
)
15381539
stack_summary.append(frame_summary)
15391540
else:
15401541
frame_summary = traceback.FrameSummary(filename_in_utf8, lineno, method_name, line=line_text)

_pydevd_bundle/pydevd_console.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""An helper file for the pydev debugger (REPL) console
2-
"""
1+
"""An helper file for the pydev debugger (REPL) console"""
2+
33
import sys
44
import traceback
55
from _pydevd_bundle.pydevconsole_code import InteractiveConsole, _EvalAwaitInNewEventLoop

_pydevd_bundle/pydevd_cython.c

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_pydevd_bundle/pydevd_cython.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ cdef class PyDBAdditionalThreadInfo:
146146
return None
147147

148148
if thread._ident is None: # Can this happen?
149-
pydev_log.critical("thread._ident is None in _get_related_thread!")
149+
pydev_log.critical("thread._ident is None in _get_related_thread! - thread: %s", thread)
150150
return None
151151

152152
if threading._active.get(thread._ident) is not thread:

_pydevd_bundle/pydevd_dont_trace.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Support for a tag that allows skipping over functions while debugging.
33
"""
4+
45
import linecache
56
import re
67

_pydevd_bundle/pydevd_frame_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ def __str__(self):
297297
__repr__ = __str__
298298

299299

300-
_cause_message = "\nThe above exception was the direct cause " "of the following exception:\n\n"
300+
_cause_message = "\nThe above exception was the direct cause of the following exception:\n\n"
301301

302-
_context_message = "\nDuring handling of the above exception, " "another exception occurred:\n\n"
302+
_context_message = "\nDuring handling of the above exception, another exception occurred:\n\n"
303303

304304

305305
def create_frames_list_from_exception_cause(trace_obj, frame, exc_type, exc_desc, memo):

_pydevd_bundle/pydevd_process_net_command_json.py

+2
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ def on_continue_request(self, py_db, request):
559559
"""
560560
arguments = request.arguments # : :type arguments: ContinueArguments
561561
thread_id = arguments.threadId
562+
if py_db.multi_threads_single_notification:
563+
thread_id = "*"
562564

563565
def on_resumed():
564566
body = {"allThreadsContinued": thread_id == "*"}

_pydevd_bundle/pydevd_runpy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _get_module_details(mod_name, error=ImportError):
166166
# pkgutil previously raised ImportError
167167
msg = "Error while finding module specification for {!r} ({}: {})"
168168
if mod_name.endswith(".py"):
169-
msg += f". Try using '{mod_name[:-3]}' instead of " f"'{mod_name}' as the module name."
169+
msg += f". Try using '{mod_name[:-3]}' instead of '{mod_name}' as the module name."
170170
raise error(msg.format(mod_name, type(ex).__name__, ex)) from ex
171171
if spec is None:
172172
raise error("No module named %s" % mod_name)

_pydevd_bundle/pydevd_save_locals.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Utility for saving locals.
33
"""
4+
45
import sys
56
from _pydevd_bundle.pydevd_constants import IS_PY313_OR_GREATER
67
from _pydev_bundle import pydev_log

_pydevd_bundle/pydevd_thread_lifecycle.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def pydevd_find_thread_by_id(thread_id):
2525
return None
2626

2727

28-
def mark_thread_suspended(thread, stop_reason: int, original_step_cmd: int=-1, main_suspend: bool=True):
28+
def mark_thread_suspended(thread, stop_reason: int, original_step_cmd: int = -1, main_suspend: bool = True):
29+
pydev_log.info("Marking thread suspended. Name: %s, stop_reason: %s, main_suspend: %s", thread.name, stop_reason, main_suspend)
2930
info = set_additional_thread_info(thread)
3031
info.suspend_type = PYTHON_SUSPEND
3132
if original_step_cmd != -1:
@@ -78,6 +79,11 @@ def resume_threads(thread_id, except_thread=None):
7879
internal_run_thread(t, set_additional_thread_info=set_additional_thread_info)
7980

8081

82+
from _pydevd_bundle.pydevd_constants import ForkSafeLock
83+
84+
suspend_threads_lock = ForkSafeLock()
85+
86+
8187
def suspend_all_threads(py_db, except_thread):
8288
"""
8389
Suspend all except the one passed as a parameter.

_pydevd_bundle/pydevd_traceproperty.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""For debug purpose we are replacing actual builtin property by the debug property
2-
"""
1+
"""For debug purpose we are replacing actual builtin property by the debug property"""
2+
33
from _pydevd_bundle.pydevd_comm import get_global_debugger
44
from _pydev_bundle import pydev_log
55

_pydevd_bundle/pydevd_vars.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
""" pydevd_vars deals with variables:
2-
resolution/conversion to XML.
1+
"""pydevd_vars deals with variables:
2+
resolution/conversion to XML.
33
"""
4+
45
import pickle
56
from _pydevd_bundle.pydevd_constants import get_frame, get_current_thread_id, iter_chars, silence_warnings_decorator, get_global_debugger
67

78
from _pydevd_bundle.pydevd_xml import ExceptionOnEvaluate, get_type, var_to_xml
89
from _pydev_bundle import pydev_log
910
import functools
10-
from _pydevd_bundle.pydevd_thread_lifecycle import resume_threads, mark_thread_suspended, suspend_all_threads
11+
from _pydevd_bundle.pydevd_thread_lifecycle import resume_threads, mark_thread_suspended, suspend_all_threads, suspend_threads_lock
1112
from _pydevd_bundle.pydevd_comm_constants import CMD_SET_BREAK
1213

1314
import sys # @Reimport
@@ -337,10 +338,11 @@ def on_timeout_unblock_threads():
337338

338339
finally:
339340
if on_timeout_unblock_threads is not None and on_timeout_unblock_threads.called:
340-
mark_thread_suspended(curr_thread, CMD_SET_BREAK)
341-
py_db.threads_suspended_single_notification.increment_suspend_time()
342-
suspend_all_threads(py_db, except_thread=curr_thread)
343-
py_db.threads_suspended_single_notification.on_thread_suspend(tid, curr_thread, CMD_SET_BREAK)
341+
with suspend_threads_lock:
342+
mark_thread_suspended(curr_thread, CMD_SET_BREAK)
343+
py_db.threads_suspended_single_notification.increment_suspend_time()
344+
suspend_all_threads(py_db, except_thread=curr_thread)
345+
py_db.threads_suspended_single_notification.on_thread_suspend(tid, curr_thread, CMD_SET_BREAK)
344346

345347

346348
def _evaluate_with_timeouts(original_func):

_pydevd_frame_eval/vendored/bytecode/bytecode.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ def __iter__(self):
175175

176176
def _check_instr(self, instr):
177177
if not isinstance(instr, (Label, SetLineno, Instr)):
178-
raise ValueError(
179-
"Bytecode must only contain Label, " "SetLineno, and Instr objects, " "but %s was found" % type(instr).__name__
180-
)
178+
raise ValueError("Bytecode must only contain Label, SetLineno, and Instr objects, but %s was found" % type(instr).__name__)
181179

182180
def _copy_attr_from(self, bytecode):
183181
super()._copy_attr_from(bytecode)

_pydevd_frame_eval/vendored/bytecode/cfg.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def __iter__(self):
2121
index += 1
2222

2323
if not isinstance(instr, (SetLineno, Instr)):
24-
raise ValueError("BasicBlock must only contain SetLineno and Instr objects, " "but %s was found" % instr.__class__.__name__)
24+
raise ValueError("BasicBlock must only contain SetLineno and Instr objects, but %s was found" % instr.__class__.__name__)
2525

2626
if isinstance(instr, Instr) and instr.has_jump():
2727
if index < len(self):
28-
raise ValueError("Only the last instruction of a basic " "block can be a jump")
28+
raise ValueError("Only the last instruction of a basic block can be a jump")
2929

3030
if not isinstance(instr.arg, BasicBlock):
3131
raise ValueError(

_pydevd_frame_eval/vendored/bytecode/concrete.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __iter__(self):
137137
def _check_instr(self, instr):
138138
if not isinstance(instr, (ConcreteInstr, SetLineno)):
139139
raise ValueError(
140-
"ConcreteBytecode must only contain " "ConcreteInstr and SetLineno objects, " "but %s was found" % type(instr).__name__
140+
"ConcreteBytecode must only contain ConcreteInstr and SetLineno objects, but %s was found" % type(instr).__name__
141141
)
142142

143143
def _copy_attr_from(self, bytecode):
@@ -249,7 +249,7 @@ def _assemble_lnotab(first_lineno, linenos):
249249
continue
250250
# FIXME: be kind, force monotonic line numbers? add an option?
251251
if dlineno < 0 and sys.version_info < (3, 6):
252-
raise ValueError("negative line number delta is not supported " "on Python < 3.6")
252+
raise ValueError("negative line number delta is not supported on Python < 3.6")
253253
old_lineno = lineno
254254

255255
doff = offset - old_offset
@@ -646,7 +646,7 @@ def to_concrete_bytecode(self, compute_jumps_passes=None):
646646
if not modified:
647647
break
648648
else:
649-
raise RuntimeError("compute_jumps() failed to converge after" " %d passes" % (pas + 1))
649+
raise RuntimeError("compute_jumps() failed to converge after %d passes" % (pas + 1))
650650

651651
concrete = ConcreteBytecode(
652652
self.instructions,

_pydevd_frame_eval/vendored/bytecode/flags.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def infer_flags(bytecode, is_async=None):
6262
bytecode,
6363
(_bytecode.Bytecode, _bytecode.ConcreteBytecode, _bytecode.ControlFlowGraph),
6464
):
65-
msg = "Expected a Bytecode, ConcreteBytecode or ControlFlowGraph " "instance not %s"
65+
msg = "Expected a Bytecode, ConcreteBytecode or ControlFlowGraph instance not %s"
6666
raise ValueError(msg % bytecode)
6767

6868
instructions = bytecode.get_instructions() if isinstance(bytecode, _bytecode.ControlFlowGraph) else bytecode
@@ -150,9 +150,7 @@ def infer_flags(bytecode, is_async=None):
150150
# next set the GENERATOR flag if relevant
151151
else:
152152
if sure_async:
153-
raise ValueError(
154-
"The is_async argument is False but bytecodes " "that can only be used in async functions have " "been detected."
155-
)
153+
raise ValueError("The is_async argument is False but bytecodes that can only be used in async functions have been detected.")
156154

157155
if maybe_generator:
158156
flags |= CompilerFlags.GENERATOR

_pydevd_frame_eval/vendored/bytecode/instr.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ class FreeVar(_Variable):
123123

124124
def _check_arg_int(name, arg):
125125
if not isinstance(arg, int):
126-
raise TypeError("operation %s argument must be an int, " "got %s" % (name, type(arg).__name__))
126+
raise TypeError("operation %s argument must be an int, got %s" % (name, type(arg).__name__))
127127

128128
if not (0 <= arg <= 2147483647):
129-
raise ValueError("operation %s argument must be in " "the range 0..2,147,483,647" % name)
129+
raise ValueError("operation %s argument must be in the range 0..2,147,483,647" % name)
130130

131131

132132
if sys.version_info < (3, 8):
@@ -169,7 +169,7 @@ def __init__(self, name, arg=UNSET, *, lineno=None, offset=None):
169169
def _check_arg(self, name, opcode, arg):
170170
if name == "EXTENDED_ARG":
171171
raise ValueError(
172-
"only concrete instruction can contain EXTENDED_ARG, " "highlevel instruction can represent arbitrary argument without it"
172+
"only concrete instruction can contain EXTENDED_ARG, highlevel instruction can represent arbitrary argument without it"
173173
)
174174

175175
if opcode >= _opcode.HAVE_ARGUMENT:
@@ -181,25 +181,25 @@ def _check_arg(self, name, opcode, arg):
181181

182182
if self._has_jump(opcode):
183183
if not isinstance(arg, (Label, _bytecode.BasicBlock)):
184-
raise TypeError("operation %s argument type must be " "Label or BasicBlock, got %s" % (name, type(arg).__name__))
184+
raise TypeError("operation %s argument type must be Label or BasicBlock, got %s" % (name, type(arg).__name__))
185185

186186
elif opcode in _opcode.hasfree:
187187
if not isinstance(arg, (CellVar, FreeVar)):
188-
raise TypeError("operation %s argument must be CellVar " "or FreeVar, got %s" % (name, type(arg).__name__))
188+
raise TypeError("operation %s argument must be CellVar or FreeVar, got %s" % (name, type(arg).__name__))
189189

190190
elif opcode in _opcode.haslocal or opcode in _opcode.hasname:
191191
if not isinstance(arg, str):
192-
raise TypeError("operation %s argument must be a str, " "got %s" % (name, type(arg).__name__))
192+
raise TypeError("operation %s argument must be a str, got %s" % (name, type(arg).__name__))
193193

194194
elif opcode in _opcode.hasconst:
195195
if isinstance(arg, Label):
196-
raise ValueError("label argument cannot be used " "in %s operation" % name)
196+
raise ValueError("label argument cannot be used in %s operation" % name)
197197
if isinstance(arg, _bytecode.BasicBlock):
198-
raise ValueError("block argument cannot be used " "in %s operation" % name)
198+
raise ValueError("block argument cannot be used in %s operation" % name)
199199

200200
elif opcode in _opcode.hascompare:
201201
if not isinstance(arg, Compare):
202-
raise TypeError("operation %s argument type must be " "Compare, got %s" % (name, type(arg).__name__))
202+
raise TypeError("operation %s argument type must be Compare, got %s" % (name, type(arg).__name__))
203203

204204
elif opcode >= _opcode.HAVE_ARGUMENT:
205205
_check_arg_int(name, arg)

_pydevd_frame_eval/vendored/bytecode/peephole_opt.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Peephole optimizer of CPython 3.6 reimplemented in pure Python using
33
the bytecode module.
44
"""
5+
56
import opcode
67
import operator
78
import sys

_pydevd_frame_eval/vendored/bytecode/tests/test_cfg.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,9 @@ def test_to_code(self):
555555

556556
if OFFSET_AS_INSTRUCTION:
557557
# The argument of the jump is divided by 2
558-
expected = b"|\x05" b"r\x04" b"|\x00" b"}\x05" b"d\x01" b"}\x05" b"|\x05" b"S\x00"
558+
expected = b"|\x05r\x04|\x00}\x05d\x01}\x05|\x05S\x00"
559559
else:
560-
expected = b"|\x05" b"r\x08" b"|\x00" b"}\x05" b"d\x01" b"}\x05" b"|\x05" b"S\x00"
560+
expected = b"|\x05r\x08|\x00}\x05d\x01}\x05|\x05S\x00"
561561

562562
code = bytecode.to_code()
563563
self.assertEqual(code.co_consts, (None, 3))

build_tools/names_to_rename.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Helper module to hold the names to rename while doing refactoring to convert to pep8.
33
"""
4+
45
NAMES = """
56
# sendCaughtExceptionStack
67
# sendBreakpointConditionException

0 commit comments

Comments
 (0)