[Stackless] Problem Unpickling Class
Andrew Francis
andrewfr_ice at yahoo.com
Mon Jul 31 14:34:08 CEST 2006
Hello Grant, Richard, and Colleagues:
>This may or may not be your problem, but keep in mind
>that you're pickling the INSTANCES, not the classes.
If >you don't manually import the classes themselves,
then >__class__ is going to point to a bad object.
>If you import the appropriate classes first, it might
>work.
I thought about your explanation. Yes I pickle
instances. However in the unpickled code, I
conventionally import the classes, so they are there.
No different from a normal programme.
>This has made me a little weary of pickling tasklets
>that are running class methods instead of functions.
Outside of the error which I believe is in my code, I
have not had problems pickling class methods or
channels. Still it brothers me that I cannot reproduce
my problem.
Here is some sample code I have used for testing.
~
import stackless
"""
ShutdownTest4.py
July 30, 2006
Trying to find the problem.
Status - failed to reproduce it.
"""
from runtime.scheduler.stackless.Synchronizer1
import Synchronizer
import sys
import time
import cPickle as pickle
class A(object):
def __init__(self):
pass
def execute(self):
self.__process__(self.x)
def __process__(self, routine):
routine()
def x(self):
print "method x is called"
class B(A):
def __init__(self):
super(B, self).__init__()
class C(B):
def __init__(self, synchronizer):
super(C, self).__init__()
self.synchronizer = synchronizer
def execute(self):
count = 0
while (1):
print "calling super class", count
super(C, self).__process__(self.x)
print "returning"
self.synchronizer.join()
count = count + 1
class ShutdownTest(object):
def __init__(self):
pass
def testOne(self):
sync = Synchronizer(1)
c = C(sync)
task = stackless.tasklet(c.execute)()
"""
ensure that required tasklets are blocked on
synchronizer
"""
while (sync.getCount() < 1):
stackless.schedule()
print "got here"
print "pickling tasklet"
f = open("sampleTasklet.dat","w")
pickle.dump(task, f)
f.close()
print "done"
print "pickling synchronizer"
f = open("sampleChannel.dat","w")
pickle.dump(sync,f)
f.close()
print "done"
while (stackless.getruncount() > 1):
stackless.schedule()
def testTwo(self):
sync = Synchronizer(1)
print "restoring synchronizer"
f = open("sampleChannel.dat","r")
sync = pickle.load(f)
f.close()
print "restoring tasklet"
f = open("sampleTasklet.dat","r")
tasklet = pickle.load(f)
f.close()
print "start the synchronizer"
sync.proceed()
while (stackless.getruncount() > 1):
stackless.schedule()
test = ShutdownTest()
test.testOne()
test.testTwo()
__________________________________________________
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