I have lighttpd web server running on my Windows 7 pc using port 80. My web app calls python cgi scripts. I am trying to configure VScode to debug these python scripts when I click a button on one of my html pages. For example:
http://localhost/cgi-bin/instantlight.py?Input=&lightColor=blue
In my launch.json file I have:
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"port": 80,
"secret": "my_secret",
"host": "localhost"
}
When I launch the debugger and click a button, my breakpoint is never hit. After a minute or two I get the error message "Debug adapter process has terminated unexpectedly"
What am I missing?
You don't need to attach to a running process as you're launching the server yourself locally (you only need attach if you're attaching to a server you don't start up yourself). So you can use the e.g. Python: Current File configuration.
Related
We have a python app on Windows which we have packaged using pyinstaller. And now the scenario is, after running the built myapp.exe, we want to be able to attach to it and do some debugging using VS Code. This was originally working on our release version (let's say the bundle is myapp-release.exe) . However, after some modifications/upgrade, when we want to do the same thing to our latest development version (let's call it myapp-dev.exe), we got the error saying timed out waiting for debug server to connect. Basically we didn't change anything in our VS Code side (so the question title can also be like "VS Code is able to attach to one python process but fails with another one, using the same launch setting". The routine is, we start the myapp-release.exe/myapp-dev.exe outside of vs code. and launch an attach task defined in launch.json:
configurations": [
{
"name": "Python: Attach using Process Id",
"type": "python",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
I know there is not really too much information given about the myapp itself. But my question is, where I can see the error logs abou the python attach procedure, to see why it fails to attach?
Thank you very much!
You can configure logging as follow:
configurations": [
{
"name": "Python: Attach using Process Id",
"type": "python",
"request": "attach",
"processId": "${command:pickProcess}",
"logToFile": true
}
]
The log files will be available in dir:
~/.vscode-server/extensions/ms-python.python-
I am curious to know if anyone successfully attached a debugger to a python script -
which is actually an Azure Function App running in a container.
I have all the VSCODE extensions but still can't seem to connect to the running container.
I've run the container from docker-compose.debug and from Bash cmd:
$ docker run -p 5678:5678 -it -e AzureWebJobsStorage="UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://host.docker.internal" nfunc:latest
NB I have to set an environment variable AzureWebJobsStorage for the storage.
My launch.json as follows:
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "0.0.0.0",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
},
What am I missing please ..
Can Functions Apps be debugged at all in a container?
Why does it not hit a breakpoint ?
Thank you
In this case, I believe you'll have to do the profiling. You will have to follow these:
If its not a blessed image, then first you would have to install SSH
if you want to get into the container.
Then you will have to make use of tools such as cProfile or other related python modules to profile the code.
Here is a documentation for windows application. You might want to take a look :
https://azureossd.github.io/2017/09/01/profile-python-applications-in-azure-app-services/index.html
This issue has been tracked : https://github.com/Azure/azure-functions-docker/issues/17
I try to debug program which is launched on Docker container using VS Code and ptvsd.
Debugger configuration:
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"port": 9091,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src"
}
]
File which should be debugged:
import ptvsd
ptvsd.enable_attach(address=('0.0.0.0', 9091))
ptvsd.wait_for_attach()
while True:
print('elo') # breakpoint is set here
I run container with open port 9091 and code inside container. Then start debugger.
Debugger is attached but it doesn't stop on breakpoint and runs infinite loop.
ptvsd is installed on local and remote with the same version - 4.2.7
What should be changed to make debugger stop on breakpoint?
I also faced the same issue, but here the work around.
Try the following:-
import ptvsd
ptvsd.enable_attach(address=('0.0.0.0', 9091))
ptvsd.wait_for_attach()
while True:
breakpoint() #this command will add the breakpoint which will detected by debugger
print('elo')
I have a virtual machine running a python process and I want to debug it from my host.
My virtual machine ip is 192.168.10.20.
As per the instructions I set up my launch.json as
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"localRoot": "/Users/wrkspace",
"remoteRoot": "/home/wrkspace",
"port": 3000,
"secret": "my_secret",
"host": "192.168.10.20"
},
I have two files,one on my host machine and on my vm called test.py which is a helloworld asking for a user input
My host machine has this at the top of the file
ptvsd.enable_attach("my_secret", address = ('192.168.10.20'3000))
# Enable the line of source code below only if you want the application
to wait until the debugger has attached to it
#ptvsd.wait_for_attach()
While on my vm, where I want to debug
ptvsd.enable_attach("my_secret", address = ('192.168.10.20'3000))
# Enable the line of source code below only if you want the application
to wait until the debugger has attached to it
ptvsd.wait_for_attach()
Once I run my attached debugger and then I kick of the test on my vm by going python test.py. It looks like it does something but then fails with
There was an error in starting the debug server.
Error="code":"ENETUNREACH","errno":"ENETUNREACH","syscall":"connect","address":"192.168.10.20","port":3000}
There was an error in starting the debug server. Error = {"code":"ENETUNREACH","errno":"ENETUNREACH","syscall":"connect","address":"192.168.10.20","port":3000}
Is there something I'm missing?
A few steps to trouble shoot these:
1) test the debug port to make sure it is open using "nc -zv test.com 30302"
2) make sure your webserver is not reloading the app after debugger was connected to it. this is the option for flask: " use_reloader=False"
I am having my remote(ubuntu 16.04) drive mounted on my local system(ubuntu 16.04) so that I can edit the source files by opening them in vscode.
Also, in the integrated terminal I can ssh to remote system and run the program using remote python interpreter which is installed on virtual environment like:
$ssh username#remoteip
$workon remotevirtualenv
(remotevirtualenv)$python source.py
I want to enable remote debugging so that if I run the debug/run the remote files, the vscode which is installed on my local system uses my remote python interpreter.
I went through the docs suggesting the use of ptvsd extension(which asks to have 2 copies of source files one on local, another one server) but I am not sure how to configure it in this scenario.
Appreciate the help. Thanks.
Edit 1:
As, I said I have gone through the docs but I am not clear how to configure in this scenario. e.g. docs say
In the source code on both computers, add the following lines, replacing my_secret with the appropriate passphrase to authenticate
remote debugging, and replacing address with the appropriate IP
address (or localhost) and port number:
ptvsd.enable_attach("my_secret", address = ('0.0.0.0', 3000))
But I have only one copy of source file i.e. on remote system. I have just mounted it on my local file system. So, should I give my local ip address or it should be remote system ip and which port number should I use as I am having only one copy of source and hence ptvsd, how is it going to communicate.
Also, in the configuration, what should I use for localRoot location and remoteRoot location.
3. {
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"port": 3000,
"secret": "my_secret",
"host": "localhost"
}
Edit: Thanks to remote development extension in VSCode, remote debugging is super easy now.
You need to put the remote ip address in both ptvsd.enable_attach("my_secret", address = ('remote_ip_address', 3000)) and in launch.json:
{
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/user1/scripts/",
"port": 3000,
"secret": "my_secret",
"host": "remote_ip_address"
}
You also need to change the remoteRoot value to the path of the directory where the script is located in the remote machine (e.g. /home/user1/scripts/).
Finally, open an ssh connection: ssh -L 3000:localhost:3000, run your script in the remote machine and attach the debugger in the local machine.
Please see the official docs on how to do remote debugging.