debugging Python调试,语言服务器问题

epggiuax  于 2022-12-29  发布在  Python
关注(0)|答案(1)|浏览(540)

在Mac OS 11.6上运行VS代码1.74.2的Python调试器时,我遇到了一些重复出现的问题。我决定遵循存储库“reporting issues”文章中的一些建议,关闭所有扩展。除了工作明显需要的扩展之外,我关闭了所有扩展,除了核心Python扩展。关闭PyLance和所有与Jupyter有关的东西。没有什么帮助,我的问题以一种不同的形式出现。
1.正确地说,进行Python调试所需的最小扩展集是什么?它比Python核心扩展更多吗?
1.在这种情况下,语言服务器到底是什么?有人能给我指一个“从头开始”的文档,并解释这个概念是怎么回事吗?
1.我希望能得到一些帮助来解释我在日志文件中看到的内容以及如何使用它。看起来我在Python扩展代码中看到了一个实际的bug,但我需要另一双眼睛。

来自1-Python.log的代表性示例:

[ERROR 2022-11-28 15:16:37.609]: [
  'Failed to start language server, Class name = h, completed in 1956ms, has a falsy return value, Arg 1: <Uri:/Users/ken/Shoshin/UI>, Arg 2: {"id":"/usr/local/bin/python3","sysPrefix":"/Library/Frameworks/Python.framework/Versions/3.9","envType":"Global","envName":"","envPath":"","path":"/usr/local/bin/python3","architecture":3,"sysVersion":"3.9.7 (v3.9.7:1016ef3790, Aug 30 2021, 16:39:15) \\n[Clang 6.0 (clang-600.0.57)]","version":{"raw":"3.9.7","major":3,"minor":9,"patch":7,"build":[],"prerelease":["final","0"]},"displayName":"Python 3.9.7 64-bit","detailedDisplayName":"Python 3.9.7 64-bit"}, Return Value: undefined',
  [Error: Launching Jedi language server using python failed, see output.
    at l.start (/Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/out/client/extension.js:2:19756)]
]
[ERROR 2022-11-28 15:16:37.609]: [
  'Failed to activate a workspace, Class name = f, completed in 2036ms, has a falsy return value, Arg 1: <Uri:/Users/ken/Shoshin/UI/try/HelloWorld.py>, Return Value: undefined',
  [Error: Launching Jedi language server using python failed, see output.
    at l.start (/Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/out/client/extension.js:2:19756)]
]
[ERROR 2022-11-28 15:16:37.609]: Failure during activation. [Error: Launching Jedi language server using python failed, see output.
    at l.start (/Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/out/client/extension.js:2:19756)]
[ERROR 2022-11-28 15:16:37.609]: sendStartupTelemetry() failed. [Error: Launching Jedi language server using python failed, see output.
    at l.start (/Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/out/client/extension.js:2:19756)]
DAP Server launched with command: /usr/local/bin/python3 /Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /usr/local/bin/python3 /Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/pythonFiles/lib/python/debugpy/adapter

来自3-Python语言服务器日志的相应材料:

Traceback (most recent call last):
  File "/Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/pythonFiles/run-jedi-language-server.py", line 11, in <module>
    sys.exit(cli())
  File "/Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/pythonFiles/lib/jedilsp/jedi_language_server/cli.py", line 125, in cli
    SERVER.start_io()
  File "/Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/pythonFiles/lib/jedilsp/pygls/server.py", line 225, in start_io
    self.loop.run_until_complete(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/ken/.vscode/extensions/ms-python.python-2022.21.13491005/pythonFiles/lib/jedilsp/pygls/server.py", line 56, in aio_readline
    header = await loop.run_in_executor(executor, rfile.readline)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 814, in run_in_executor
    executor.submit(func, *args), loop=self)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 170, in submit
    self._adjust_thread_count()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 193, in _adjust_thread_count
    t.start()
TypeError: start() missing 1 required positional argument: 'sessionID'
[Error - 3:16:39 PM] The Python Jedi server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 3:16:39 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 3:16:39 PM] Python Jedi client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 3:16:39 PM] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097

切换到PyLance语言服务器后:

[Info  - 7:36:39 AM] (39856) Pylance language server 2022.12.20 (pyright 621d886b) starting
[Info  - 7:36:39 AM] (39856) Server root directory: /Users/ken/.vscode/extensions/ms-python.vscode-pylance-2022.12.20/dist
[Info  - 7:36:39 AM] (39856) Starting service instance "UI"
[Info  - 7:36:39 AM] (39856) Notebook support: Legacy
[Info  - 7:36:39 AM] (39856) Interactive window support: Legacy
[Info  - 7:36:39 AM] (39856) Auto-indent enabled
[Info  - 7:36:39 AM] (39856) No configuration file found.
[Info  - 7:36:39 AM] (39856) No pyproject.toml file found.
[Info  - 7:36:39 AM] (39856) Setting pythonPath for service "UI": "/usr/local/bin/python3"
[Warn  - 7:36:39 AM] (39856) stubPath /Users/ken/Shoshin/UI/typings is not a valid directory.
[Info  - 7:36:39 AM] (39856) Assuming Python version 3.9
[Info  - 7:36:39 AM] (39856) Assuming Python platform Darwin
[Info  - 7:36:39 AM] (39856) Searching for source files
[Info  - 7:36:39 AM] (39856) Found 61 source files
[Info  - 7:36:39 AM] (39856) Background analysis(1) root directory: /Users/ken/.vscode/extensions/ms-python.vscode-pylance-2022.12.20/dist
[Info  - 7:36:39 AM] (39856) Background analysis(1) started
[Info  - 7:44:45 AM] (39856) Indexer background runner(2) root directory: /Users/ken/.vscode/extensions/ms-python.vscode-pylance-2022.12.20/dist (index)
[Info  - 7:44:45 AM] (39856) Indexing(2) started
[Info  - 7:44:45 AM] (39856) scanned(2) 238 files over 1 exec env
[Info  - 7:44:48 AM] (39856) [IDX(2)] Long operation: index execution environment /Users/ken/Shoshin/UI (2240ms)
[Info  - 7:44:48 AM] (39856) [IDX(2)] Long operation: index packages /Users/ken/Shoshin/UI (2243ms)
[Info  - 7:44:48 AM] (39856) indexed(2) 154 files over 1 exec env
[Info  - 7:44:48 AM] (39856) Indexing finished(2).
isr3a4wc

isr3a4wc1#

进行Python调试所需的最小扩展集是什么?
这就是Python扩展,它包含了编写、运行和调试Python代码所需的一切,包括语言服务器。
日志中显示*Jedi*语言服务器可能有问题。请将python.languageServer配置修改为pylance

"python.languageServer": "Pylance",

相关问题