PTVS hangs on run through without breakpoints

Jul 11, 2013 at 10:36 AM
Hi there,

First off PTVS looks absolutely AWESOME (just download the binary to give it a try after reading about it on hanselman.com) big thanks to the team for their efforts!!

I have come across a strange issue though, but this may very well be because of my limited knowledge of the environment and may be compounded by limited knowledge of Python!

Whenever I try to run/debug a project from the VS2013 Preview (Django, console) it does nothing at all (it just hangs) UNLESS I put in a breakpoint somewhere at the start. This does seem to give it some time to warm up the engines (Python interpreter?) and start up the Django development server or display a Window through SDL etc.

Does anyone have any idea why this might be? (I am using Windows 7 & Python 2.7)

Many thanks,

Martijn
Coordinator
Jul 12, 2013 at 9:57 PM
Thanks for the kind words, it's not immediately obvious why this might be happening, but hopefully we can figure it out and get it fixed. I have some questions to hopefully track down what's happening:

When you say "Django, console" are you using the Django management console to run? Or is this just a normal F5 launch w/ debugging?

Is VS unresponsive or is just nothing happening? Can you look in task manager and see if a python.exe process is created? And does Ctrl-F5 (launch w/o debugging) work?
Jul 14, 2013 at 11:02 AM
Thank you for your reply. Sorry for the lack of detail in my post, I have currently only created two projects and both display this behaviour, one is a standard Django project (from template), the other is a console project with a reference to the PySDL2 library and draws a simple Window to the screen. I have no access to my laptop atm but will post a detailed break down this week. Just off the top of my head it seemed like this behaviour was displayed using the Debug button but not when right clicking on .py file and choosing to run it from there but I will confirm this later (I will also check the task manager).
Jul 15, 2013 at 7:14 PM
I'm seeing the exact same issue. If I F5 a project with no breakpoints, the python.exe window opens empty and just sits there. After a few minutes, my web browser opens but can't connect to the server. If I insert a breakpoint, even on an empty line, everything works as expected.
Coordinator
Jul 15, 2013 at 8:07 PM
Ok, I suspect I know what this is now. Can you try waiting for a long time after the browser open and see if the site eventually comes up?

We had one issue reported which is a bug in another VS component fixed internally in VS 2013. The result is that launching debugging can be extremely slow to start, and it gets worse with the number of modules loaded in the app. Django loads a lot of modules, so it could be this issue.

We have a possible workaround for previous versions of VS but we've been trying to gauge how much of an issue this is in the real world. If Django eventually launches then it's probably this issue. I've seen it take 1 minute, and I've even seen it take multiple minutes to launch. If it does succeed and you can let us know how long it takes that'd be useful information as well.
Jul 20, 2013 at 7:44 PM
I have been experiencing the same issue, with no Django or web anywhere in the picture.
I just have a main python program that hangs when I start the debugging (F5), and I had to put a breakpoint in the start of the code to get things working.

Environment:
Windows 7 Ultimate
Python 2.7.5
PTVS 2.0 beta
VS 2012 Professional
Jul 30, 2013 at 12:09 PM
Same here, but i found something...

I reduced my source code to:
import sys
import numpy
print('Hello World')

1)with F5 from visual studio this will hang with empty console window. (ill tried waiting for few minutes)
2)if i add breakpoint to line with "print('Hello World')", Debugger will stop at breakpoint in less than 1 second after F5
3)if i delete "import numpy" it will not hang, write the "hello world" to output and close the console window (as expected from code)

Environment:
Windows 7 professional
Python 2.7
PTVS 2.0 beta
VS 2012 Premium

Python enviroment:
Python 2.7.5 64bit from python.org
decorator (3.4.0)
distribute (0.6.45)
memoize (1.0.0)
numpy (1.7.1) from http://www.lfd.uci.edu/~gohlke/pythonlibs/
pillow (2.1.0) from http://www.lfd.uci.edu/~gohlke/pythonlibs/
pip (1.4)
pycuda(2013.1.1)
pytools(2013.5.6)
Coordinator
Jul 30, 2013 at 10:47 PM
bgale & ttxman - the somewhat good news is that i recreated your environments & cannot repro your bug.
Jul 31, 2013 at 1:00 AM
OK. I downloaded the pdb symbols and enabled "native mode debugging". With "native mode debugging" it does not stuck...

Now it takes approximately 15 seconds after F5 until "hello world" is showed in the console window (python.exe).

Here is my debug output I don't like the lines with "exceptions.TypeError", can someone tell me if they are problem?

I will probably try clean install tomorrow.
Coordinator
Jul 31, 2013 at 4:03 AM
They are not the problem. Those are exceptions that are raised and caught by Python import machinery when importing modules (and, occasionally, by the modules themselves). For mixed-mode native/Python debugging, we don't have the concept of "caught" and "uncaught" exceptions yet - they are all treated as raised but potentially caught, so they never break by default. To avoid confusing people when an exception occurs, therefore, all exceptions are reported to the Output window at the point where they are raised.

This exception design is tentative and not necessarily final, so any feedback on what you would rather prefer to see is welcome.

The 15-second startup delay is also a known issue, and is actually also caused by the standard library, but in a different way - we have a somewhat expensive hook that fires whenever a new code object is created, which basically translates to every class and function definition, and there is a lot of those implicitly triggered even by a simple hello world. I'm looking into ways to speed this up.
Jul 31, 2013 at 8:55 AM
OK i will try something else... :)
Aug 1, 2013 at 8:45 PM
I can confirm that I have the same issue. Without a breakpoint anywhere in the code, the program would not execute and it just gets stuck. I have tried a clean install and also tried it on multiple versions (2012, 2013 etc) and machines. This was not an issue with the alpha release of 2.0 however. Please let me know what information i can provide to help diagnose the problem.
Aug 1, 2013 at 9:39 PM
Edited Aug 1, 2013 at 9:40 PM
I'd tried complete reinstall of python and PTVS it not helped. I also tried a different PC (windows 8 x64) and installed python for all users, then only for one user, didn't helped too.

The windows 7 one is after clean installation, so i can tell common software and settings.

software:
Visual studio (2012 premium)
complete .NET SDKs (and help),
windows SDKs to get VC10 c++ compilers.
Notepad++
Opera browser
windows defender (win8 have integrated something like that)

system confing
disabled UAC
SSD as main disk
disabled hibernation
fixed swap to 1GB


Only thing i can think of is my Visual studio , it is from the MSDNAA so it can be slightly different (maybe)?
Coordinator
Aug 1, 2013 at 10:18 PM
arvmenon, do you have this problem on all your projects, or just for one particular project? If the latter, can you list the packages that you have imported there?

Also, can you try doing the same thing ttxman did for his repro - commenting out specific imports and seeing if that makes any difference. If this is something that has to do with specific packages, or something that only some packages have in common, we'd love to narrow down on them to get a better chance at reproducing the problem so that we can debug it.
Aug 1, 2013 at 11:12 PM
I uninstalled the 2.0 beta, and installed the 2.0 alpha. I can confirm, there is no stuck in the alpha build...
Aug 2, 2013 at 10:59 AM
pminaev, this happens with all of my projects.

My regular imports are
PySide
future.print_function
numpy
pandas

I can try commenting out specific imports and see what it does. Will report back.
Coordinator
Aug 6, 2013 at 11:45 PM
Folks,

We think we have a fix for this issue. Can you please download these two files & try them before we call it good?

Thanks!

http://sdrv.ms/13EsPFh
Aug 7, 2013 at 8:11 AM
Edited Aug 7, 2013 at 8:18 AM
OK i tried the files :) and YES it is fixed it for me..
Aug 15, 2013 at 8:38 PM
I verified that the files fixed the same problem in VS 2010. So you might call it good. Thanks!
Sep 5, 2013 at 8:41 AM
Verified with VS 2012 and VS 2013 for Windows 8. Thanks
Coordinator
Sep 10, 2013 at 8:43 PM
RC build is out and includes the fix.
Nov 8, 2014 at 8:09 PM
Ptools wrote:
Folks,

We think we have a fix for this issue. Can you please download these two files & try them before we call it good?

Thanks!

http://sdrv.ms/13EsPFh
Hello,
I was reading through the various posts and I appear to have the same issue with my program hanging at start up.
Eventually it will run but it takes a excessively long time to get past the import statements.
I am running MS Visual Studio Express 2013 for Desktops with the PTVS 2.1 tool on Windows 7.
My program consists of the following two lines:

from pyalgotrade.barfeed import yahoofeed
print('Hello World')



In the post above there is reference to some files that fixed the issue. When I click the link the files are no longer available.
Please let me know if there is a solution to this issue that I can try and where I can find it.

Thanks!
Coordinator
Nov 8, 2014 at 10:18 PM
The fix is already in 2.1, so there's something else causing your issue.

Is pyalgotrade a public library? Where can I get a copy to test?
Nov 9, 2014 at 3:06 AM
Zooba wrote:
The fix is already in 2.1, so there's something else causing your issue.

Is pyalgotrade a public library? Where can I get a copy to test?
PyAlgoTrade can be found here.

http://gbeced.github.io/pyalgotrade/

Thanks
Coordinator
Nov 13, 2014 at 5:18 PM
Thanks for that. I've had a chance to look today and it seems that importing that module will also import numpy, and numpy does quite a lot of expensive operations on import (such as compiling regexes). Depending on how the packages have been installed (.egg vs. folder) and your exception settings, this can take a long time to get through, and you should see a similarly long delay from just importing numpy.

Without knowing more about how your packages have been installed (a file listing of your site-packages folder would show me) and what exception settings you have selected, I can't suggest any workarounds other than disabling Just My Code (through Debug, Options menu), which will also disable breaking when exceptions are raised. We do hope to improve exception notifications at some point, which will probably help with this, but that will be in a later PTVS version.