1

I have a C# environment in which I use IronPython scripts. I want to debug these using Visual Studio i.e. PTVS. I set everything up and it does work, but it works only once. After I stop the debugger or the scripts ends, I cannot attach to the process again or hit a breakpoint. Apart from being very slow this is something that really strucks me because I want to be able to process my script multiple times without closing the whole application everytime.

Does anyone have experience with this kind of debugging and knows how to make it more comfortable?

Versions:

  • VS10 (C#), VS12 (PTVS 2.2)
  • .NET 4.0
  • IronPython 2.7.0.40
Marcel Bonzelet
  • 238
  • 2
  • 13
  • What kind of attach are you using? Are you attaching using Managed code type, or Python, or both? – Pavel Minaev Dec 18 '15 at 10:05
  • I am using the files in the 'ptvsd' folder. Calls are 'ptvsd.enable_attach(secret='MySecret')', 'ptvsd.wait_for_attach()', 'ptvsd.break_into_debugger()', ... – Marcel Bonzelet Dec 18 '15 at 10:17
  • Do you have tried to use a newer version of IronPython? I don't know if some thing changed at this point, but maybe `2.7.6` will do the trick. – BendEg Dec 18 '15 at 10:20
  • Afaik 2.7.6 is not released yet, the same goes for IronPython 3. And in this case I don't think that IronPython is responsible for the bad debugging environment. – Marcel Bonzelet Dec 18 '15 at 10:25
  • The problem is that from PTVS's perspective, every time you run a Python script, it's like a whole new Python process. Once the script exits, there isn't really anything that debugger can do to stay attached, because there's nothing to attach to there - the Python interpreter loop is not running. – Pavel Minaev Dec 18 '15 at 19:09
  • But why wouldn't I be able to attach again if I start the same script twice? If it's like a whole new process that's what I would expect. – Marcel Bonzelet Dec 18 '15 at 20:22
  • Because all the `ptvsd` stuff that you have set up also "goes away" with that "process". – Pavel Minaev Jan 12 '16 at 22:29

1 Answers1

0

My suggestion is that instead of using ptvsd-based attach, you try regular attach (where you just go to Debug -> Attach to Process, and select your .exe), and select a combination of Native, Managed and Python code types to enable mixed-mode debugging. This has some other benefits (like you'll be able to step from C# code to Python and back), and should also work around the problem that you're seeing. It's limited in other ways compared to pure Python debugging, but you may find the limitations acceptable.

Pavel Minaev
  • 99,783
  • 25
  • 219
  • 289
  • I will try that out, I didn't know that I could enable mixed-mode with .NET and Python together. – Marcel Bonzelet Dec 18 '15 at 20:23
  • Just be sure that you also enable Native - it won't work well without that, even if you don't actually utilize it. – Pavel Minaev Dec 19 '15 at 00:17
  • I just tried to enable mixed-mode but I wasn't able to use it. I found many sites on the net where they debug a python project but I have a managed one. And I also wasn't able to check python and managed/native code at the same time in the Attach to process window, it says they are not compatible. – Marcel Bonzelet Dec 21 '15 at 08:52
  • If your startup project is C#, then you'll have to use Attach; the project itself doesn't know anything about Python (unfortunately, this is something that every project system handles on its own, and usually in a non-extensible way). As for Attach not working - it indicates that you're using VS 2010 (and so also an old version of PTVS), which lacks mixed-mode support. If at all possible, I would strongly recommend upgrading to VS 2015 + PTVS 2.2.2. – Pavel Minaev Dec 21 '15 at 22:06