[Stackless] Problem Unpickling Class

Andrew Francis andrewfr_ice at yahoo.com
Thu Jul 27 02:34:15 CEST 2006


Hello Colleagues:

I am having problems deserializing a class. 

In the following test, I have a class,
ExperimentalScheduler. ExperimentalScheduler inherits
from SchedulerDaemon.

I wish to pickle ExperimentalScheduler. I will
unpickle ExperimentalScheduler some time in the future
and have it resume execution in the future.

def testTwo(self):
        """
        the daemon communicates through channels
        """
        requestChannel = stackless.channel()
        responseChannel = stackless.channel()

        channels = [requestChannel, responseChannel]
        tasks = []
        
        """
        the synchronizer is used to join threads of
        execution
        """
        synchronizer = Synchronizer(3)

        """
        A test scheduler daemon
        """
        server = ExperimentalDaemon("experimental",  
                                    requestChannel, 
                                    responseChannel, \
                                    synchronizer)
        server.setDebugLevel(1)

       
tasks.append(stackless.tasklet(server.startInputProcessing)())
     
tasks.append(stackless.tasklet(server.startOutputProcessing)())
       
stackless.tasklet(Pump(requestChannel).execute)()
        
        """
        wait for two threads to join
        """
        while (1):
            if synchronizer.getCount() == 2:
                break
            stackless.schedule()
            
        print "the scheduler is blocked"
        
        print stackless.getruncount()
        
        """
        it is now safe to pickle the scheduler
        pickle the scheduler and all the appropriate
        channels
        """
        f = open("synchronizer.dat","w")
        pickle.dump(synchronizer, f)
        f.close()
        
        """
        past tests indicate I need to pickle the 
        channels and the synchronizer
        """
        f = open("channels.dat","w")
        pickle.dump(channels,f)
        f.close()
        
        """
        and the scheduler
        """
        f = open("tasklets.dat","w")
        pickle.dump(tasks, f)
        f.close()

        f = open("server.dat","w")
        pickle.dump(server, f)
        f.close()
        
        print "we are finished writing"


The method in the SchedulerDaemon (which is inherited
by ExperimentalDaemon) is :


import stackless
from   AbstractDaemon     import AbstractDaemon


def __processCommand__(self, channel, routine):
    
        while(1):
            
            super(SchedulerDaemon,
self).__processCommand__(channel, routine)
            
            
            """
            wait for a command from the main 
            application
            """
           
            self.synchronizer.join()
            
            if (self.debugLevel > 0):
                print "[" + self.name + " woke up]"
                
        print "I SHOULD NEVER GET HERE"        

The pickling goes fine. However when I unpickle (use
pickle.load), I get the following error - 

NameError: global name 'AbstractDaemon' is not defined

I check the pickled data files. I see references to
AbstractDaemon. I run another test using dir(),
__class_, __dict__, and __bases__. I see the right
methods and superclasses. 

At this stage I am not quite sure what is happening.
The only clue I see is in the pickle documentation I
see something about new style classes and setstate().
Any insights would be appreciated.

Cheers,
Andrew















__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list