• lua 写逻辑打印log时,打印到一半后停止不再打印,程序停止


    问题描述:ubuntu下用lua开发游戏电子邮件模块,自己测试时向用户推送100封,而用户最多只能有50封。这是调用sysdelete删除一些邮件。当打印log时,打印到一半后程序中途停止。将打印log的代码删除后又恢复正常。

    目前估计是缓存满了。待解决。。删除邮件代码如下:

    function _M:sysdelemail()
      local readrewarded = {}
      local readunrewarded = {}
      local unread = {}

      for k , v in pairs( self.__data ) do
        if 1 == v.isread then
          if 1 == v.isreward then
            table.insert( readrewarded , v.csv_id )
          else
            table.insert( readunrewarded , v.csv_id )
          end
        else
          local tmp = {}
          tmp.csv_id = v.csv_id
          tmp.acctime = v.acctime
          table.insert( unread , tmp )
        end
      end
    --delete read and getrewarded first

      for _ , v in ipairs( readrewarded ) do
        local tmp = self.__data[ tostring( v ) ]
        tmp.isdel = 1
        tmp:__update_db( { "isdel" } )
        self.__data[ tostring( v ) ] = nil
        self.__count = self.__count - 1
      end

      if self.__count <= self.__MAXEMAILNUM then
        return
      end
    -- if still more than MAXEMAILNUMM then delete read , unrewarded
      for _ , v in ipairs( readunrewarded ) do
        local tmp = self.__data[ tostring( v ) ]
        tmp.isdel = 1
        tmp:__update_db( { "isdel" } )
        self.__data[ tostring( v ) ] = nil
        self.__count = self.__count - 1
      end

      if self.__count <= self.__MAXEMAILNUM then
        return
      end
    -- last delete the earlist unread emails
      table.sort( unread , function ( ta , tb ) return ta.acctime < tb.acctime end )

      --[[ 如果在此打印排序后的邮件列表变回出现描述的问题打印到一半结束,去掉后却正常

        for k , v in ipairs( unread ) do

          print( k , v )

        end

      --]]

      local diff = self.__count - self.__MAXEMAILNUM
      print( "sizeof diff is ****************************************" , diff , #unread )
      local tmp = {}
      for i = 1 , diff do
        tmp = self.__data[ tostring( unread[ i ].csv_id ) ]
        assert( tmp )
        tmp.isdel = 1
        tmp:__update_db( { "isdel" } )
        self.__data[ tostring( unread[ i ].csv_id ) ] = nil

        self.__count = self.__count - 1
      end
      print( "sizeof unread is ****************************************" , self.__count )
    end

      

      昨天以为是缓存区满了,但今天又测试的一下,输出更多的log,没有出现昨天的问题。纠结中,现在用的是 skynet 框架 ,仍在学习中。感觉这会是个定时炸弹,不知哪天爆了。希望用skynet并pengdao过类似问题的同学不吝赐教。。 

  • 相关阅读:
    nput keyup 500ms 延时输入 事件处理
    browser-sync默认地址如何转成127.0.0.1
    overflow:scroll-css知识备忘
    圆角的css样式
    支付宝开发
    C#代码与javaScript函数的相互调用
    高性能web开发 如何加载JS,JS应该放在什么位置?
    Makefile自动生成头文件依赖
    一步步教你如何写Makefile
    (一):U-BOOT启动分析--概述
  • 原文地址:https://www.cnblogs.com/newbeeyu/p/5252927.html
Copyright © 2020-2023  润新知