gpt4 book ai didi

Python 线程 - 参数数量错误

转载 作者:太空狗 更新时间:2023-10-30 00:22:30 25 4
gpt4 key购买 nike

我在一个线程中执行了将近 25k 次的命令,例如

if threaded is True:
thread = Thread(target=threadedCommand, args=(cmd))
thread.start()
thread.join()

def threadedCommand(command):
if command is None:
print 'can\'t execute threaded command'
sys.exit(-1)
print 'executing - %s'%(command)
os.system(command)

命令就像

cp file dir

我看到的是

Traceback (most recent call last): File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "/usr/lib64/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) TypeError: threadedCommand() takes exactly 1 argument (52 given)

^CException in thread Thread-9377: Traceback (most recent call last): File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "/usr/lib64/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) TypeError: threadedCommand() takes exactly 1 argument (56 given)

最佳答案

args 必须是元组。 (cmd) 等同于cmd;你想要一个单元素元组:

thread = Thread(target=threadedCommand, args=(cmd,))
# ^

关于Python 线程 - 参数数量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7392636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com