0
我已经定义了以下装饰:装饰可以访问原来的功能
def loop_callback(func):
"""Only works in programs with a single main loop. Can call .sameThread
to access the original unwrapped function directly"""
@wraps(func)
def wrapped_func(*args, **varargs):
if mainThread==threading.current_thread():
print("We are in the loop thread")
func(*args, **varargs)
else:
print("In another thread")
loop.add_callback(lambda: func(*args, **varargs))
wrapped_func.orig=func
return wrapped_func
的想法是,你应该能够通过调用类似myObject.myFunction.orig(arg1, arg2)
访问原始功能。不幸的是,orig
不会收到自我对象,只是arg1
和arg2
。有没有什么办法解决这一问题,以便它可以被称为我想要的方式?