多处理TypeError

jam*_*s02 3 python multiprocessing typeerror

我有这个代码:

import multiprocessing as mp
import shutil
import md5

def f(src,dst):
    shutil.copy2(src,dst)

file_1 = "C:\Users\Nick\Documents\production\TEST\\test.txt"    
file_2 = "C:\Users\Nick\Documents\production\TEST_2\\test.txt"

def get_md5(file_name):
    with open(file_name) as file_to_check:
        # read contents of the file
        data = file_to_check.read()    
        # pipe contents of the file through
        md5_returned = md5.new(data).hexdigest()
        print md5_returned

if __name__ == '__main__':
    P = mp.Process(target=f, args=(file_1,file_2))
    s = mp.Process(target=get_md5, args=(file_1))
    P.start()
    P.join()
    s.start()
    s.join()
Run Code Online (Sandbox Code Playgroud)

我现在只测试如何使用多处理,但get_md5函数会抛出类型错误.错误信息是这样的:

Traceback (most recent call last):  
  File "C:\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap  
    self.run()  
  File "C:\Python27\lib\multiprocessing\process.py", line 114, in run  
    self._target(*self._args, **self._kwargs)  
TypeError: get_md5() takes exactly 1 argument (48 given)
Run Code Online (Sandbox Code Playgroud)

它看起来好像get_md5进程只有一个参数,我不知道48个参数来自哪里.

有人可以帮忙吗?

ven*_*npa 8

我想,你必须将args作为元组传递:

s = mp.Process(target=get_md5, args=(file_1,))
Run Code Online (Sandbox Code Playgroud)

你错过了逗号.如果您错过了逗号,则file_1中的各个字符将被视为单独的args.

编辑:

包括亚当·斯密的反应,我认为适合上下文:

它看起来像Process接受*args**kwargs,当你把它这意味着r"C:\Users\Nick\Documents\production\TEST\\test.txt"它将遍历它给*args == ["C",":","\\","U","s","e","r","s","\\","N", ... ]