PyCharm 3.1 在索引期间永远挂起并且无法使用
问题描述
更新到 3.1 后,PyCharm 在索引"包期间永远挂起(在 OSX 10.9.1、Python 2.7.5 上).
After updating to 3.1, PyCharm hangs forever (on OSX 10.9.1, Python 2.7.5) during the "indexing" of packages.
对我来说,这发生在索引 scipy
(0.13.3) 时.如果我卸载 scipy
,索引似乎已完成,但随后又挂在pythonstubs"上.UI 变得无响应,CPU 使用率达到最大值,我无法执行任何操作,不得不强制退出应用程序.
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.
如果我重新安装 scipy,PyCharm 会在 scipy 扫描的同一位置再次挂起(请参阅对话框的屏幕截图):
If I reinstall scipy, PyCharm hangs again at the same spot in the scipy scan (see screen capture of dialog):
FWIW,我可以毫无问题地从系统命令行运行 Python 脚本(包括一些使用 scipy
和许多其他最近更新或安装的软件包),因此 Python 安装是正确的.
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?
解决方案
问题在于任何可能已定义用于识别 TODO 项的正则表达式匹配.PyCharm 用于匹配这些项目的 Java 标准正则表达式库使用指数复杂度的算法来搜索 '*.a'
和类似模式.
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.
Python re 模块也存在同样的问题:
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
一般来说,如果索引需要很长时间或挂起,请查看 TODO 项中的正则表达式,看看是否可以缩小匹配范围以提高性能.
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.
相关文章