|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如题
- import threading
- def testfunc(class_name):
- class_name.class_test()
- class Test_A():
- def __init__(self):
- pass
- def class_test(self):
- print("test")
- a = Test_A()
- test_thread = threading.Thread(target = testfunc, args = (a))
- test_thread.start()
复制代码
这段代码运行会报错:TypeError: testfunc() argument after * must be an iterable, not Test_A
如果我要传递一个类对象作为参数,我应该放弃这种创建线程函数的方法吗?
如果元组中只有一个元素,那么末尾要加逗号
- import threading
- def testfunc(class_name):
- class_name.class_test()
- class Test_A():
- def __init__(self):
- pass
- def class_test(self):
- print("test")
- a = Test_A()
- test_thread = threading.Thread(target = testfunc, args = (a,))
- test_thread.start()
复制代码
|
|