将python list和dictionary设置为None需要很多时间

2024-09-30 03:23:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个代码:

        rows_to_process = EulerNightlyDBQueries.fetchRowsToProcess(cur_date, Config.config_dict['settings']['Performance']['euler_nightly_rows_to_process'], Config.config_dict['settings']['Data']['recover_mode'])
        mac_uniques_hour, \
        emp_mac_uniques_hour, \
        mac_uniques_hour_monthly = EulerNightlyDBQueries.fetchMacUniquesByDate(cur_date)

        #Start processing raw rows from receiver table
        try:
            RawProcessor.startRawProcessor(cur_date, mac_uniques_hour, emp_mac_uniques_hour, rows_to_process)
            emp_mac_uniques_hour = None
            rows_to_process = None

注意“rows_to_process”(数据库中的行列表)和“emp_mac_uniques_hour”(数据库值字典)。在

假设我为每个行提取了800000行。 当我做:

^{pr2}$

需要45-120秒!! 这不就是把列表和字典的引用改成“无”?? 为什么要花这么长时间。。??在

我这样做是为了让GC在我处理完它们之后能够收集它们。。 顺便说一下,我使用的是python2.7.6

谢谢!在


Tags: tononeconfigdatesettingsmacprocessdict
1条回答
网友
1楼 · 发布于 2024-09-30 03:23:30

I'm doing this in order to the GC to be able to collect them after I'm done with them.. By the way, I'm using python 2.7.6

CPython的GC不是这样工作的。它主要执行引用计数,并且只将标记样式GC作为检测引用循环的最后手段。因此,如果这是对对象的最后一次引用,那么将其设置为None将释放该对象(以此类推)。在

如果您想将必要的GC工作推迟到以后,您可以创建对数据的另一个引用,并将设置为None later。或者我想你可以尝试设计一个引用循环,但这看起来很复杂。在

不过,在我看来,2分钟对于不到100万个数据库行来说还是很长时间。在

相关问题 更多 >

    热门问题