functions and variables lost after reimport

Issue #1 new
Jie Shi created an issue

As the title says, python code got exceptions after reimport which result in serious data loss.

Comments (5)

  1. Peter Peter repo owner

    Do you have the exception or stack trace? The code will already precheck the module for syntax errors. If there were any exceptions while importing the module then it tries to "rollback" so that nothing gets modified.

  2. Jie Shi reporter

    Good morning, Peter. It's 23pm here so maybe tmr I can post an exception or traceback for you. Reimport project has been used in a game server. Each time we put a hotupdate patch( game logic, game data), It must lost some data and member functions. Like reset players' level to 0. For example, all players who is level 16 will be set to 0. Also any data whose value is 16 will be reset to 0. PS. Server runs on linux. Windows seems to corrupt the data at lower chances.

  3. Jie Shi reporter
    logger = xxx.getLogger()
    class A:
        def method(self):          
              def callback(result):
                    global logger
                    logger.debug(...)
              async(callback)
    

    This is the pseudo code for previous traceback. logger is Nonetype after reimport.

  4. Jie Shi reporter

    After several experiments it's obvious when Closure changed reimport would collapse the data within the closure function.

  5. Peter Peter repo owner

    I can see why this is a tricky case. As a workaround, you could implement a reimported function in your module that gets called whenever the module is reimported?

    def __reimported__(previous):
        globals()["logger"] = previous.logger
        return True
    
  6. Log in to comment