मैं cpickle का उपयोग कर दूरस्थ वातावरण में फ़ंक्शन को लोड करने का प्रयास कर रहा हूं। लेकिन मुझे त्रुटि मिली "मॉड्यूल" ऑब्जेक्ट में कोई विशेषता नहीं है ... "। कहाँ मैं वास्तव में अटक नाम स्थान पहले से ही जिम्मेदार बताते हैं कि, भले ही यह लोड करने के लिए कृपया मददविशेषताएँ त्रुटि: 'मॉड्यूल' ऑब्जेक्ट में कोई विशेषता नहीं है (सीपीकल का उपयोग करते समय)
import inspect
import cPickle as pickle
from run import run
def get_source(func):
sourcelines = inspect.getsourcelines(func)[0]
sourcelines[0] = sourcelines[0].lstrip()
return "".join(sourcelines)
def fun(f):
return f()
def fun1():
return 10
funcs = (fun, fun1)
sources = [get_source(func) for func in funcs]
funcs_serialized = pickle.dumps((fun.func_name,sources),0)
args_serialized = pickle.dumps(fun1,0)
#Creating the Environment where fun & fun1 doesnot exist
del globals()['fun']
del globals()['fun1']
r = run()
r.work(funcs_serialized,args_serialized)
यहाँ run.py है विफल रहता है शामिल है
import cPickle as pickle
class run():
def __init__(self):
pass
def work(self,funcs_serialized,args_serialized):
func, fsources = pickle.loads(funcs_serialized)
fobjs = [compile(fsource, '<string>', 'exec') for fsource in fsources]
#After eval fun and fun1 should be there in globals/locals
for fobj in fobjs:
try:
eval(fobj)
globals().update(locals())
except:
pass
print "Fun1 in Globals: ",globals()['fun1']
print "Fun1 in locals: ",locals()['fun1']
arg = pickle.loads(args_serialized)
त्रुटि
Fun1 in Globals: <function fun1 at 0xb7dae6f4>
Fun1 in locals: <function fun1 at 0xb7dae6f4>
Traceback (most recent call last):
File "fun.py", line 32, in <module>
r.work(funcs_serialized,args_serialized)
File "/home/guest/kathi/python/workspace/run.py", line 23, in work
arg = pickle.loads(args_serialized)
AttributeError: 'module' object has no attribute 'fun1'
है
तो fun1 है मॉड्यूल में एकीकृत, चलाने कहना –