Remote debugging in linux.

May 10 at 2:39 PM
Hi Guys,

I am having trouble setting up the remote debug feature.

I have very limited access to the linux machine that i need to debug on, I have uploaded the ptvsd folder as the video on youtube suggests but when i try to connect to that host to find the python process this fails.

I really have only ssh access to the linux box.

Is this possible to setup in this way ?

Many thanks

John Dowling
Coordinator
May 10 at 9:15 PM
It should be quite possible. In fact, you don't even need to upload ptvsd, normally, as it is available on PyPI, so you can just pip install ptvsd (if you're using 2.1 beta, you need to specify the version number explicitly - pip install ptvsd==2.1.0b1).

I assume you have followed the rest of the process as described in the video, i.e. did import ptvsd; ptvsd.enable_attach(...) in the script you're trying to debug.

Can you tell a bit more about how you're trying to attach, and how exactly that fails - what error messages you're getting etc.

Also, one thing that's worth checking is whether the Linux machine you're connecting to is behind a firewall. You might need to open the debugger port (5678 by default, though you can override that if needed - see enable_attach docstring for details) if that's the case.
May 11 at 8:08 AM
Edited May 11 at 8:09 AM
Hi pminaev,

I did a little more testing an it seems that i am having trouble with the server script itself, when i try to run my script i get the following python error.
[Linux]$ python Main.py
Traceback (most recent call last):
  File "Main.py", line 5, in ?
    import ptvsd
  File "/home/john/Python_Projects/Project_Pipes/V1.0/ptvsd/__init__.py", line 17, in ?
    from ptvsd.attach_server import enable_attach, wait_for_attach, break_into_debugger, settrace, is_attached, AttachAlreadyEnabledError
  File "/home/john/Python_Projects/Project_Pipes/V1.0/ptvsd/attach_server.py", line 264
    finally:
          ^
Here is the version info that i am running
Microsoft Visual Studio 2013 Shell (Integrated)
Version 12.0.21005.1 REL
Microsoft .NET Framework
Version 4.5.50938

Installed Version: IDE Standard

Microsoft Visual C# 2013

Microsoft Python Tools for Visual Studio   2.0.11016.00
Python Tools for Visual Studio provides intellisense, project support, project and item templates, as well as a REPL window for Python development.

Microsoft Python Tools for Visual Studio - Django Integration   2.0.11016.00
Provides templates and integration for the Django web framework.

Microsoft Python Tools for Visual Studio - Profiling Support   2.0.11016.00
Profiling support for Python projects.

NuGet Package Manager   2.7.40911.287
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

SQL Server Data Tools   12.0.30919.1
Microsoft SQL Server Data Tools
Any help with this is much appreciated


Many thanks

John
Coordinator
May 11 at 8:11 AM
It looks like the error message from Python is truncated - there should be more after the line with ^.

Also, which Python version are you using on that server?
May 11 at 9:04 AM
Hi pminaev

Sorry i cut one line from the output.
[Linux]$ python Main.py
Traceback (most recent call last):
  File "Main.py", line 4, in ?
    import ptvsd
  File "/home/john/Python_Projects/Project_Pipes/V1.0/ptvsd/__init__.py", line 17, in ?
    from ptvsd.attach_server import enable_attach, wait_for_attach, break_into_debugger, settrace, is_attached, AttachAlreadyEnabledError
  File "/home/john/Python_Projects/Project_Pipes/V1.0/ptvsd/attach_server.py", line 264
    finally:
          ^
SyntaxError: invalid syntax
Version
Python 2.4.3
Coordinator
May 11 at 10:19 AM
I suspected it would be something along these lines. PTVS only supports Python 2.5 or later (though, generally speaking, the latest major release is always recommended). It looks like remote attach does not do any version checks, and hence you don't get a coherent error message explaining what exactly is wrong.
May 11 at 10:26 AM
Hi pminaev,

Thanks for the reply, I don't control the version of python used as this is a shared platform :-(.

It is a shame, i cant seem to find any type of IDE that i can use for this work. Is there a version that i can downgrade to to get this functionality ?

Many Thanks

John
Coordinator
May 11 at 10:37 AM
I'm afraid that for PTVS, there's no such version - I'm not sure if it ever supported 2.4, but it certainly did not do so when remote debugging was originally added, so that piece of code was never tested on 2.4 at all.

PyDev seems to claim support for 2.4, and they also have remote debugging - you could try that.

If nothing works, then your best bet is probably to use the stock debugger (pdb) - it's not fancy, but for many simple cases it will get the job done, and since it's text-based, you can drive it over an ssh connection easily.
May 14 at 8:38 PM
Hi Guys,

ok so i have managed to use a version of python unknown to me on the server (2.6), the script is now running.

I have run into an issue now that i have to use the non standard debugging port.

I have changed the script to use the open port but i can see the server is still using the default port. Below is the line used in the script.
ptvsd.enable_attach ( address = ('0.0.0.0', 443))
but when i do a netstat i can see that it is opening the default port.
[LINUX ~]$ netstat -an |grep 5678 |grep LISTEN
tcp        0      0 0.0.0.0:5678                0.0.0.0:*                   LISTEN
[LINUX ~]$ netstat -an |grep 443 |grep LISTEN
[LINUX ~]$
Any ideas ?

thanks

John
Coordinator
May 14 at 9:22 PM
Are you sure that the server has actually been restarted with the new code?
May 14 at 9:27 PM
Hi pminaev,

The code was already there, i just didn't know (it is not the default)

as above i can see the script opening the remote debugging port 5678 even when i have specified the new port. I know that it is the script opening this as i have done nestats before and after the running the script and i can see the port being opened and closed with the script.

Thanks for the help with this


John
Coordinator
May 15 at 12:59 AM
Looking at the line of code you use:
ptvsd.enable_attach ( address = ('0.0.0.0', 443))
This should actually not work at all, because it does not specify the secret, which is a mandatory parameter (even if you just pass None to it). What you should see in the output of the script is something like this:
  File "test.py", line 3, in <module>
    ptvsd.enable_attach(address = ('0.0.0.0', 6666))
TypeError: enable_attach() takes at least 1 argument (1 given)
That this is not the case further reinforces my belief that you're somehow ending up with an older version of your script being used. In particular, if you're using some web server to host your scripts, it might cache them in memory, or copy them somewhere else on the disk.

Or, perhaps, there's more than one call to enable_attach in your script, and it's the other one (which uses the default port) that's actually executing?
May 17 at 10:34 AM
Hi Guys,

Once again thanks for the support here, you guys are awesome. I was being a twat and my script updates were not being updated on the remote machine as i had expected.

I am getting the port opened at the moment, i will let you how i get on.