Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

pydevd errors (NoneType not attribute add_command; PyDB no attribute _py_db_command_thread_event) #1688

Closed
mgsnuno opened this issue Aug 13, 2019 · 8 comments

Comments

@mgsnuno
Copy link

mgsnuno commented Aug 13, 2019

Environment data

  • PTVSD version: 4.3.1
  • OS and version: Linux/4.19.66-1-MANJARO manjaro/18.0.4
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.4
  • Using VS Code or Visual Studio: None

Actual behavior

File "<stdin>", line 1, in <module>
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/attach_server.py", line 101, in enable_attach
    ptvsd_enable_attach(address)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_remote.py", line 79, in enable_attach
    patch_multiprocessing=ptvsd.options.multiprocess)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2174, in settrace
    wait_for_ready_to_run,
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2223, in _locked_settrace
    debugger = PyDB()
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 395, in __init__
    self._files_filtering = FilesFiltering()
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py", line 125, in __init__
    library_roots = self._get_default_library_roots()
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py", line 161, in _get_default_library_roots
    roots.append(sysconfig.get_path(path_name))
  File "/home/nuno/miniconda3/lib/python3.7/sysconfig.py", line 521, in get_path
    return get_paths(scheme, vars, expand)[name]
  File "/home/nuno/miniconda3/lib/python3.7/sysconfig.py", line 511, in get_paths
    return _expand_vars(scheme, vars)
  File "/home/nuno/miniconda3/lib/python3.7/sysconfig.py", line 172, in _expand_vars
    _extend_dict(vars, get_config_vars())
  File "/home/nuno/miniconda3/lib/python3.7/sysconfig.py", line 559, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/home/nuno/miniconda3/lib/python3.7/sysconfig.py", line 430, in _init_posix
    _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
  File "/home/nuno/miniconda3/lib/python3.7/_sysconfigdata_m_linux_x86_64-linux-gnu.py", line 700, in <module>
    GCC_VERSION = check_output([GCC, '--version'], stderr=err).decode('utf-8').splitlines()[0].split(' ')[-1]
  File "/home/nuno/miniconda3/lib/python3.7/subprocess.py", line 395, in check_output
    **kwargs).stdout
  File "/home/nuno/miniconda3/lib/python3.7/subprocess.py", line 472, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/home/nuno/miniconda3/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/home/nuno/miniconda3/lib/python3.7/subprocess.py", line 1453, in _execute_child
    restore_signals, start_new_session, preexec_fn)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 447, in new_fork_exec
    send_process_created_message()
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 540, in send_process_created_message
    debugger.send_process_created_message()
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 1519, in send_process_created_message
    self.writer.add_command(cmd)
AttributeError: 'NoneType' object has no attribute 'add_command'
File "<stdin>", line 1, in <module>
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/attach_server.py", line 101, in enable_attach
    ptvsd_enable_attach(address)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_remote.py", line 79, in enable_attach
    patch_multiprocessing=ptvsd.options.multiprocess)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2174, in settrace
    wait_for_ready_to_run,
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2253, in _locked_settrace
    debugger.start_auxiliary_daemon_threads()
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 1783, in start_auxiliary_daemon_threads
    self._create_pydb_command_thread()
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 1771, in _create_pydb_command_thread
    new_pydb_command_thread = self.py_db_command_thread = PyDBCommandThread(self)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 152, in __init__
    self._py_db_command_thread_event = py_db._py_db_command_thread_event
AttributeError: 'PyDB' object has no attribute '_py_db_command_thread_event'
File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 672, in get_file_type
    return _cache_file_type[cache_key]
KeyError: (2117, '/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py', <code object settrace at 0x7f20b6e431e0, file "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2117>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/attach_server.py", line 101, in enable_attach
    ptvsd_enable_attach(address)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_remote.py", line 79, in enable_attach
    patch_multiprocessing=ptvsd.options.multiprocess)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2174, in settrace
    wait_for_ready_to_run,
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2279, in _locked_settrace
    debugger.set_trace_for_frame_and_parents(get_frame().f_back)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 1748, in set_trace_for_frame_and_parents
    file_type = self.get_file_type(frame)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 700, in get_file_type
    file_type = self._internal_get_file_type(abs_real_path_and_basename)
  File "/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 617, in _internal_get_file_type
    return self._dont_trace_get_file_type(basename)
AttributeError: 'PyDB' object has no attribute '_dont_trace_get_file_type'

Expected behavior

no errors.

Steps to reproduce:

(bash)

  1. conda create -n test_ptvsd
  2. conda install -n test_ptvsd pip
  3. pip install ptvsd
  4. python

(python)

  1. import ptvsd
  2. ptvsd.enable_attach(address=('localhost', 0))
  3. ptvsd.enable_attach(address=('localhost', 0)) (again same line, different second error)
  4. ptvsd.enable_attach(address=('localhost', 0)) (again same line, different third error)
@fabioz
Copy link
Contributor

fabioz commented Aug 13, 2019

Can you give the full tracebacks?

All errors seem to imply that PyDB is not properly initialized before being used...

The first error appears to be because a new process is created (but without the full traceback I can't say whether this is new process from a fork or a new process through subprocess or exec).

@mgsnuno
Copy link
Author

mgsnuno commented Aug 13, 2019

(edited first post.)

Further details: doesn't occur with Python 3.7.3

@fabioz
Copy link
Contributor

fabioz commented Aug 13, 2019

I see the error... ouch, it seems that during the initialization of the debugger a process is spawned (for gcc) when getting the paths from sysconfig and at that time the debugger is not properly initialized to be used when it tries to notify that that process was created. This prevents the proper initialization of the debugger (so, the other errors are just side-effects of the first error).

I think you can work around it locally by editing:

/home/nuno/miniconda3/lib/python3.7/site-packages/ptvsd/_vendored/pydevd/pydevd.py

then, in the first line in send_process_created_message (close to line 1519), change the function by adding the lines below as the first thing in the function.

if self.writer is None:
    return

Please let me know if that works...

(it seems this is something that changed on Python itself).

@mgsnuno
Copy link
Author

mgsnuno commented Aug 13, 2019

Thanks a lot. I reverted to Python 3.7.3 and solves the problem, which supports your theory.

Tried your fix and solved the problem.

What can we do to solve this issue?

@fabioz
Copy link
Contributor

fabioz commented Aug 13, 2019

I'll create a patch for this shortly...

@lhughes41
Copy link

lhughes41 commented Jul 20, 2020

Same error for me in eclipse 4.13 and 4.16 on Windows 10 with pydev 7.6.0 (was not experiencing on prior pydev. Python 3.7.

The error happened for me around this code in pydevd:
with self.suspended_frames_manager.track_frames(self) as frames_tracker:
frames_tracker.track(thread_id, frames_list)
cmd = frames_tracker.create_thread_suspend_command(thread_id, stop_reason, message, suspend_type)
self.writer.add_command(cmd)

I tried fix above and turned into an endless busy cursor. My context was calling pdev breakpoint(). I can live with the error for now as it just spews junk that I can fix the bug that cause the breakpoint. But would be nice to have fixed! Not much fun.
Thanks,
Luke
p.s. Actually a short term workaround would be appreciated. This is coming up frequently as I debug. Otherwise will have to find older pydev version.

@fabioz
Copy link
Contributor

fabioz commented Jul 21, 2020

@lhughes41 if it's an issue in plain pydevd (on Eclipse), please report it in the pydevd repo (https://github.com/fabioz/PyDev.Debugger/).

Also, please make sure you include your full stack trace and details on how you're reproducing your issue (since the original error should be fixed you probably have a different problem).

@lhughes41
Copy link

Hi @fabioz
Started here: fabioz/PyDev.Debugger#175
Luke

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants