On 10/27/13 6:18 PM, Christian Tismer wrote:
So my guess of the solution is this:
Let wingdb_import_hook report "__builtin__" as its module and
'__import__' as
its name, and you are fine.
You're right. The problem with simply using a name other than
__builtin__.__import__ is that it may not be there when a pickle is
loaded because the debugger may not be running. This is illustrated by
the attached failimp.py file. Try running:
failimp.py debug dump
failimp.py load
This simulates creating a pickle when the debugger is running and then
trying to load it when the debugger is not running. The workaround is
to set __module__ to '__builtin__' and __name__ to '__import__' on the
import_hook function.
Thanks,
John
import sys
import __builtin__
import pickle
ORIGINAL_IMPORT = __import__
DEBUG = 'debug' in sys.argv
if DEBUG:
def import_hook(*args, **kw):
return ORIGINAL_IMPORT(*args, **kw)
__builtin__.__import__ = import_hook
PICKLE_FILENAME = 'test.pickle'
class Test1(object):
def __init__(self):
self.func = lambda s: 0
def dump():
t = Test1()
with open(PICKLE_FILENAME, 'wb') as f:
pickle.dump(t, f)
def load():
with open(PICKLE_FILENAME, 'rb') as f:
t = pickle.load(f)
if 'load' in sys.argv:
load()
elif 'dump' in sys.argv:
dump()_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless