首页 > 解决方案 > 解决线程中的组参数错误

问题描述

我正在使用线程来下载、转换视频并删除它。但是,当我使用线程时,它给了我一个错误AssertionError: group argument must be None for now 线程工作正常,直到之前运行 3 次,但它突然显示此错误。

我认为 group 参数是默认的 None 但我只是在参数中添加了 'group = None' 。现在它显示一个错误说TypeError: __init__() got multiple values for argument 'group'

def video_download(parent_file, url):
    #checking if it succeed or not for logging
    fail = []
    success = []
    #which number in the list the program is in
    check = 1

    #check if the url is playlist or single video
    if url.find("list") != -1:
        pl = Playlist(url)
        links = pl.parse_links()
        #length of list
        total = len(links)
        print("\n start download")
        for l in links:
            t1 = threading.Thread(l,target= download_multi, group = None, args=(l,check,parent_file,success,fail,total))
            t1.start()
            time.sleep(1)
            t2 = threading.Thread(target= download_multi, group = None, args=(l,check,parent_file,success,fail,total))
            t2.start()
            time.sleep(1)
            t3 = threading.Thread(target= download_multi, group = None, args=(l,check,parent_file,success,fail,total))
            t3.start()
            time.sleep(1)
            t1.join()
            t2.join()
            t3.join()

没有组的错误代码 = 无

  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\pydev\pydevd.py", line 2060, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\pydev\pydevd.py", line 2054, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\pydev\pydevd.py", line 1405, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\pydev\pydevd.py", line 1412, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/paulm/Desktop/Github/git/YoutubeDownloader/main.py", line 179, in <module>
    recieve_input()
  File "C:/Users/paulm/Desktop/Github/git/YoutubeDownloader/main.py", line 37, in recieve_input
    video_download(parent_file, url)
  File "C:/Users/paulm/Desktop/Github/git/YoutubeDownloader/main.py", line 102, in video_download
    t1 = threading.Thread(l,target= download_multi, args=(l,check,parent_file,success,fail,total))
  File "C:\Users\paulm\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 786, in __init__
    assert group is None, "group argument must be None for now"
AssertionError: group argument must be None for now

组的错误代码 = 无

Traceback (most recent call last):
  File "C:/Users/paulm/Desktop/Github/git/YoutubeDownloader/main.py", line 179, in <module>
    recieve_input()
  File "C:/Users/paulm/Desktop/Github/git/YoutubeDownloader/main.py", line 37, in recieve_input
    video_download(parent_file, url)
  File "C:/Users/paulm/Desktop/Github/git/YoutubeDownloader/main.py", line 102, in video_download
    t1 = threading.Thread(l,target= download_multi, group = None, args=(l,check,parent_file,success,fail,total))
TypeError: __init__() got multiple values for argument 'group'

问题解决了。第一个线程有错字,修复后它工作得很好。

标签: python-3.xpython-multithreading

解决方案


t1 = threading.Thread(l,target=线与t2和t3不一致

额外的l被错误地视为组 arg 的默认值

错字?


推荐阅读