1
如何在传递“自己”的类方法上调用线程?我有一个类定义如下,并希望以self作为参数在新线程中调用class方法。我试过但自己没有通过作为参数在类方法上创建线程
cust_obj = Customer()
thread.start_new_thread(cust_obj.process,())
class Customer():
def __init__(self):
pass
def process(self):
self.fetch_data()
self.serialize_data()
def fetch_data(self):
# Fetch data logic
pass
def serialize_data(self):
# Serialize fetched data
pass
应该工作(关键字:绑定方法)。什么是错误信息? – delnan
这应该工作。无论如何,一个简单的解决方法可能是:'thread.start_new_thread((lambda:Customer()。process()),())' – Bakuriu
只有在声明失败时才能提供任何帮助。 –