Time out waiting for launcher to connect in VS code - python

I did python debugging in VS code.
The following is the launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"python": "${command:python.interpreterPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions":[
"RedirectOutput"
],
"console": "integratedTerminal"
}
]
}
The following is settings.json file:
{
"python.pythonPath": "c:\\Users\\susan\\Documents\\PythonScripts\\venv\\Scripts\\python.exe",
// to fix 'Timeout waiting for debugger connections'
"python.terminal.activateEnvironment" : false
}
When I debug the python script in VS code, I got Time out waiting for launcher to connect and cannot debug the python script.
May I know how can I solve this issue?

Its very simple. Open the launch.json file and add the following into it:
{
"name": "Python: Debug Console",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
Then save and exit it. Whatever you do, DO NOT clear the text already in there or else it may make it worser

If for whatever reason "internalConsole" isn't a good solution:
in your shell script:
export PROCESS_SPAWN_TIMEOUT=30
or just hack the code directly (will be reverted if you update the extension):
.vscode-server/extensions/ms-python.python-2022.18.2/pythonFiles/lib/python/debugpy/adapter/launchers.py[161]:
change:
timeout=(None if sudo else common.PROCESS_SPAWN_TIMEOUT)
to:
timeout=30,

Related

Problem in debugging django project using VS code

I have a problem while debugging a django project using VS code, the problem that nothing happened when I click to debug button, I can launch my script just by tapping in terminal python manage.py runserver.
Here is my launch.json file, and note please that I tried a lot of examples, and still the same problem:
{
"version": "0.2.0",
"configurations": [
{
"name": "Django",
"python": "C:/Users/msekmani/Desktop/dashboard_project/venv/Scripts/python.exe",
"type": "python",
"request": "launch",
"program": "C:/Users/msekmani/Desktop/dashboard_project/IPv2/src/manage.py",
"console": "internalConsole",
"args": ["runserver"],
"django": true,
"justMyCode": true,
},
]
}
I am using python version 3.6 and for the OS is Windows.
Note please that I also tried to creat a Python debug and also it's not working also, and here is my launch.json script:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
I find a solution to solve this problem by upgrade the python version to 3.7, I don't have any idea about the problem happened in version 3.6, by the way, the upgrade python version is the solution.

'No module named flask' in VSCode even when I have installed flask

I have my Flask installed in my main directory for playing with Flask projects and I don't want to change it (its name is tryFlask).
My project is in one of the subdirectories to tryFlask (main_project).
How should I config my launch.json so that it doesn't throw errors when I try to debug?
Current config which throws:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "my_app.py",
"FLASK_ENV": "tryFlask",
"FLASK_DEBUG": "1"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true,
"justMyCode": true
}
]
}
And yes I have already checked "FLASK_APP": "my_project/my_app.py". Doesn't work. Neither does reinstalling dependencies or even choosing different interpreters from venv's bin subdirectory.
If you want to use flask with vscode, following this tutorial is a good start.
According to the question in your post, if you want to specify the python interpreter when debugging, you can add the python configuration to launch.json
Simple example:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
// Modify the python interpreter with flask installed on your machine
"python": "C:\\WorkSpace\\pytest10\\.venv\\Scripts\\python.exe"
// "python": "${workspaceFolder}/.venv/Scripts/python.exe"
}
]
}
For more launch.json configuration, you can check this link.

How to debug a file from current directory with Python in VS Code?

I can see that this question has been asked multiple times already however, none of the solutions seems to be working anymore, forcing me to ask for the latest fix.
Problem
I have created a workspace in VS code with the following directory structure,
work__assignments (this is my main workspace folder in vs code)
assignment__1
data
modules
tests
assignment__2
data
modules
tests
"work__assignments" is my main workspace folder in the VS code. From this main workspace, I go to an assignment folder (e.g. work__assignments > assignment__2 > modules) and work on the respective code. However, when I try to debug the code in "work__assignments > assignment__2 > modules" the debugger loads from the main workspace folder (i.e. work__assignments), then it fails because it can't find other modules in the modules folder "work__assignments > assignment__2 > modules".
I have tried the following methods so far,
Updating the launch.json file and adding the line "cwd": "${fileDirname}",
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}"
}
Updating the launch.json file and adding the line "cwd": "",
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": ""
}
Updating the launch.json file and adding the following lines,
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"env": {
"PYTHONPATH": "${cwd}"
}
}
Updating the preferences
However, NONE OF THESE APPROACHES HAVE WORKED. Every time I debug the code, it launches into the workspace folder and not in the code folder. What am I doing wrong?
Note: I am running the debugger using the "Debug Python File" button at the top right corner as shown in the picture below,
Configure one of the following cwd in launch.json:
"cwd": "./assignment__2"
"cwd": "${fileDirname}"
It should be noted that you need to debug the program from the Run and Debug panel to execute the configuration in launch.json.
A simple example
Directory Structure and code
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
// "cwd": "./hello"
"cwd": "${fileDirname}"
}
]
}
Debug results
Invalid configuration in launch.json if debug is selected from play button

python vscode environment variables not available

I have attempted to follow the directions for environment variables in my project and thought I was doing the correct thing but it does not appear to be working when debugging my python code in vscode.
I have a launch.json for a project in .vscode/
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"envFile": "${workspaceFolder}/dev.env"
}
]
}
and a dev.env file in my project root
PYTHONUNBUFFERED=1
PASSWORD=abc123
DEBUG_SSO=user.name
CELERY_DEBUG=True
SEND_MAIL=True
when I hit a breakpoint and do "os.getenv('PASSWORD')" it returns None, even though the variable is set in dev.env.
Any idea what is wrong with this configuration?
This may be due to the relative path being unrecognized.
Add this line to the file "launch.json" : "cwd": "${fileDirname}"

VS code python debugger error with print statements

So when ever im trying to debug any Python script on VS code an that script has a print or input statement, it crashes an throws me an "AttributeError" that says 'NoneType' object has no attribute 'write', any ideas why this happens? i cant find any information on Google about it
here is a screenshot in the error:Link to the screenshot
and also here is my configuration file:
{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
}
]
}
VSCODE working fine for me
a) Install VSCODE or upgrade to version 1.28.1
b) REFRESH Python Extension
If you face any issue like timeout etc read
https://github.com/Microsoft/vscode-python/issues/2410
very carefully
Edit settings.json of python extension
a) Disable
Terminal: Activate Environment
Activate Python Environment in Terminal created using the Extension.
b) enable
Terminal: Execute In File Dir
When executing a file in the terminal, whether to use execute in the file's directory, instead of the current open folder.
c) Remove pythonW and put python in
Python Path
Path to Python, you can use a custom version of Python by modifying this setting to include the full path.
Everything above from
https://github.com/Microsoft/vscode-python/issues/2410
Though a happy ending I can foresee a future of unstable releases
for a wonderful VSCODE and even better Python Extension
An attribute error usually means that whatever object your working with is actually none. This can happen because something happened upstream or downstream of your call.
In the case of your single print statement, the only thing I can think of is perhaps it has something do so with double quotes.. It doesn't really make sense that double quotes would cause this but who knows.
what happens when you try
print('I will crash!!!')
If that still fails then I would say that perhaps vs is trying to write to a file, configuration, log, console or something else and is running into permission issues.
EDIT
After looking closesr at your configuration files, I see you have two that start with
"name": "Python: Current File ....
So I rewrote your config file, it still includes the specific files that were named, and their configs, but I eliminated one of the current file entries and made it basic.
{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
},
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
}
]
}
I have it set up to use the external console (standard windows cmd). If you want to use the vs console replace
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
},
with
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"console": "integratedTerminal"
},
Do NOT forget to save a copy of your old config file first. That way if VS freaks out from manually changing this file you can always revert back.
I am looking for the possibility that VS can't decide which terminal to output too, but at the same time you only get this while debugging so....
Now I did see a flag in the config for no debug but it was for a flask app.

Categories