简体   繁体   English

PyCharm IDE 调试时速度很慢 Python 读取小 pickle 文件

[英]PyCharm IDE is very slow on debug Python reading small pickle file

Debug takes sometimes 10 seconds.调试有时需要 10 秒。 The problem starts after reading 30mega + 5 mega pickles, with with pdb debugging is fine.读取 30mega + 5 mega pickles 后问题开始,用 pdb 调试就可以了。 Even on lines of 'print'即使在“打印”行

any suggestions?有什么建议么?

if __name__ == "__main__":
    print 'loading files...',
    with open(fname1, 'rb') as handle: items = pickle.load(handle)
    with open(fname2, 'rb') as handle: sentences_by_id= pickle.load(handle)
    print ' done!'

I had a similar problem with a dict of lists of ndarrays.我对 ndarrays 列表的字典有类似的问题。 when the list was too long, the pycharm debugger would freeze, top would show cpu for the pycharm at 102% ( I guess several cores were active) and it would take a very long time to unfreeze.当列表太长时,pycharm 调试器会冻结,top 会显示 pycharm 的 cpu 为 102%(我猜有几个核心处于活动状态)并且解冻需要很长时间。 Running without breakpoints was fine.没有断点运行很好。 My solution was to convert all my lists on ndarrays to ndarrays, eg我的解决方案是将 ndarrays 上的所有列表转换为 ndarrays,例如

<pseudo python>
for k in dict_of_lists_of_ndarrays:
     dict_of_lists_of_ndarrays[k]=np.array(dict_of_lists_of_ndarrays[k])
</pseudo python>

now things are much improved.现在情况有了很大改善。 I have no idea what the issue was我不知道是什么问题

I found this thread on JetBrains support, which is suggesting to turn off "Show return values" option (you can find it in the settings of the Debug tool bar, the gear icon).我在 JetBrains support 上找到了这个线程,它建议关闭“显示返回值”选项(您可以在调试工具栏的设置中找到它,齿轮图标)。 It has solved it for me.它已经为我解决了。

I did some analysis on this, also changed my IDE to Elipse using PyDev plugin.我对此做了一些分析,还使用 ​​PyDev 插件将我的 IDE 更改为 Elipse。

Still debugging python program was way too slower than the actual directly executing python program.仍然调试python程序比实际直接执行python程序太慢。

How much slower?慢多少? It took my computationally intensive program more than 17 minutes and still no solution where when run directly, the same program returned output within 2 minutes.我的计算密集型程序花了超过 17 分钟,仍然没有解决方案,直接运行时,相同的程序在 2 分钟内返回输出。

I guess the problem is with Python Debugger, not with either of IDE's Eclipse or Jetbrains Pycharm.我想问题出在 Python 调试器上,而不是 IDE 的 Eclipse 或 Jetbrains Pycharm 上。 I can vouch for both as I have worked on both for many years.我可以为两者作担保,因为我已经在这两个方面工作了很多年。

It's worth checking if there's any explicit debugger speed setting option available for Python Debugger.值得检查是否有任何可用于 Python 调试器的显式调试器速度设置选项。

What help for me was to change the "variable loading policy" to "on demand".对我的帮助是将“可变加载策略”更改为“按需”。 This is done by clicking the small cog wheel in the debug menu.这是通过单击调试菜单中的小齿轮来完成的。 For a picture check the link:要查看图片,请查看链接:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206601625-pycharm-debugger-slow-due-to-collecting-data- https://intellij-support.jetbrains.com/hc/en-us/community/posts/206601625-pycharm-debugger-slow-due-to-collecting-data-

this happened to me (PyCharm 2019.3) and it was caused by invalid breakpoints that had been placed on files subsequently deleted, edited etc. Delete all breakpoints and make sure you haven't got a breakpoint on Exception "raise".这发生在我身上(PyCharm 2019.3),它是由放置在文件上的无效断点引起的,这些断点随后被删除、编辑等。删除所有断点并确保您没有在异常“raise”上获得断点。 Once I did that PyCharm debugging went back to normal speed一旦我这样做了 PyCharm 调试就恢复了正常速度

quite in delay, however i had similar issues that couldn't be solved for the life of me for more than a week.相当延迟,但是我遇到了类似的问题,一个多星期都无法解决我的生活。 Tried all the above, and much more.尝试了以上所有,还有更多。 Eventually, for me one of the two following solutions worked (found them in the inte.net, unfortunately can't find where, for proper credit):最终,对我来说,以下两个解决方案之一起作用了(在 inte.net 中找到它们,不幸的是无法找到适当的信用):

  1. Python Debugger -> Enable Gevent. Python 调试器 -> 启用 Gevent。
  2. Add at the beginning of the run np.set_printoptions(threshold=5).在运行开始时添加 np.set_printoptions(threshold=5)。

Can't tell why it helped - I didn't change anything in my code, including usage of gevents, when the issue started.不知道为什么它有帮助 - 当问题开始时,我没有更改我的代码中的任何内容,包括 gevents 的使用。 But, it seems to be of no harm;但是,这似乎没有什么坏处; especially option (2)...特别是选项(2)...

#voodoosolutions #voodoosolutions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM