title: Pickling Self and Return to Run-state?
body: <p>I found the following post extremely helpful:
  <a href="https://stackoverflow.com/questions/2709800/how-to-pickle-yourself">How to pickle yourself?</a></p>
  
  <p>however the limitation with this solution is that when the class is reloaded, it is not returned in its "runtime" state.  i.e. it will reload all the variables etc and the general state of the class at the moment it was dumped.. but it won't continue running from that point. </p>
  
  <p>Consider:</p>
  
  <pre><code>class someClass(object):
     def doSomething(self):
         i = 0         
         while i &lt;= 20:
            execute
            i += 1
            if i == 10:
               self.dumpState()
  
     def dumpState(self):
        with open('somePickleFile','wb') as handle:
           pickle.dump(self, handle)
  
     @classmethod
     def loadState(cls, file_name):
        with open(file_name, 'rb') as handle:
            return pickle.load(handle)
  </code></pre>
  
  <p>If the above is run, by creating an instance of someClass:</p>
  
  <pre><code> sC = someClass()
   sC.doSomething()
   sC.loadState('somePickleFile')
  </code></pre>
  
  <p>This does not return the class to its runtime state, it does not continue through the while loop until i == 20.. </p>
  
  <p>This may not be the correct approach, but I am trying to find a way to capture the runtime state of my program i.e. freeze/hibernate it, and then relaunch it after possibly moving it to another machine.. this is due to issues I have with time restrictions enforced by a queuing system on a cluster which does not support checkpointing. </p>