11

After updating to 3.1, PyCharm hangs forever (on OSX 10.9.1, Python 2.7.5) during the "indexing" of packages.

For me this occurs while indexing scipy (0.13.3). If I unistall scipy, indexing appears to complete, but then hangs again on "pythonstubs". The UI becomes unresponsive, CPU use is maxed, and I'm unable to do anything and have to force-quit the app.

If I reinstall scipy, PyCharm hangs again at the same spot in the scipy scan (see screen capture of dialog):

enter image description here

FWIW, I can run Python scripts from the system command line (including some that use scipy and many other packages recently updated or installed) without issue, so the Python installation is sound.

Has anyone had a similar problem or found a way around this one?

orome
  • 45,163
  • 57
  • 202
  • 418
  • Why are you posting here instead of opening an issue in [PyCharm's issue tracker](http://youtrack.jetbrains.com/issues/PY)? – Bakuriu Feb 05 '14 at 17:00
  • @Bakuriu: To see if anyone has "had a similar problem or found a way around this one". It is also possible that this is an obscure issue with `scipy` (recently updated on PyPi) that has scope beyond PyCharm. (And how do you know I didn't open an issue.?) – orome Feb 05 '14 at 17:03
  • This question appears to be off-topic because it is a poll. The OP just wants to know if "other people experienced the same problem", but such a question doesn't have a real answer and doesn't fit into StackOverflow's allowed topics. – Bakuriu Feb 05 '14 at 17:06
  • 1
    @That's an English idiom for introducing the request for a solution to the problem: it is likely that anyone with a solution will have "had a similar problem" (*viz.* the latest `scipy` tripping up and IDE or other software that indexes the package). – orome Feb 05 '14 at 17:09
  • Are you [using OpenJDK][1]? PyCharm apparently doesn't like it. [1]: http://stackoverflow.com/questions/11477719/pycharm-install-jdk – Jonathan Harford Jul 01 '14 at 20:30
  • @JonathanHarford: No. – orome Jul 01 '14 at 20:35

4 Answers4

5

The problem lies with any regular expression matches that may have been defined to identify TODO items. The Java standard regular expression library used by PyCharm to match these items uses an algorithm of exponential complexity to search for '*.a' and similar patterns.

Theoretically, it is possible to match any regexp very fast (a linear algorithm exists), > but many developers of regexp libs simply don't bother implementing it.

The same problem exists for the Python re module:

>>> from timeit import timeit
>>> timeit("import re; list(re.finditer('.*a', 'foo' * 10000))", number=1)
0.6927990913391113
>>> timeit("import re; list(re.finditer('.*a', 'foo' * 50000))", number=1)
17.076900005340576

In general, if indexing is taking a long time, or hanging, look to the RegEx in your TODO items and see if you can narrow the scope of matches in order to improve performance.

orome
  • 45,163
  • 57
  • 202
  • 418
  • 5
    This sounds very promising. Any chance you could explain the mechanics of how to do this part: "look to the RegEx in your TODO items and see if you can narrow the scope" ? – Ezekiel Kruglick Jun 14 '15 at 01:45
3

This is what solved it for me:

On the main menu, choose File | Invalidate Caches/Restart . The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next startup. Use buttons in the dialog to invalidate caches, restart IntelliJ IDEA or both.

My problem was probably that I added too many files to be indexes, and it overwhelmed PyCharm. So I marked the folders of the files I did not need indexed as "Excluded" and used the option above.

Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88
  • 1
    Cache cleaning has a lot of side effects. It also won't address the underlying issue with Java's RegEx library. – orome Mar 04 '15 at 12:21
  • @raxacoricofallapatorius It's unclear if that's the real issue. You're just assuming it is (and it **may** be). For me, the cache clearing did the trick after having the exact same symptoms. – Reut Sharabani Mar 04 '15 at 12:22
  • It's what JetBrains says the "real" issue is. Did cache cleaning fix it forever? Were you seeing times that grew exponentially (or at least much faster than linearly) with string length? – orome Mar 04 '15 at 12:30
  • After cache clearing IDE is booting up normally and not indexing as long. I also installed scipy yesterday and probably didn't restart since. When I did (today) - I had the exact same problemt hat cache clearing fixed. I can update if the issue persists later on, but I doubt it will. After tracking `.Pycharm40/.../idea.log` it seems like everything is back to normal. – Reut Sharabani Mar 04 '15 at 12:34
  • It never worked for me (at least not reliably), and the JetBrains advice did, permanently. – orome Mar 04 '15 at 12:38
2

I had a similar situation: I just installed Anaconda(2) and when I wanted to change interpreters it will keep indexing and crash. "Invalidate Cache" would not work. What need to be done is to add the interpreter (Project -> Project Interpreter) AND change the Run -> Edit Configurations. I got the reponse from here

Community
  • 1
  • 1
lui
  • 76
  • 3
1

I had the same problem and "File | Invalidate Caches/Restart" had not helped because Pycharm didn't respond at all. I found ".Pycharm50" directory in my home directory -- it contains configuration files. After it's removal Pycharm launched as if you've just downloaded it, everything still goes well.