我定义了以下装饰器:
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
的是,不会收到 self 对象,只是arg1
and arg2
。有没有办法解决这个问题,以便可以按照我想要的方式调用它?