import glob, os
import tarfile
import concurrent.futures
def function(file1,arc):
print(file1)
arc.add(file1)
destination="/home/lol/org"
src=["a","b"]
for i in src:
if not os.path.exists(os.path.join(destination,i)):
os.mkdir(os.path.join(destination,i))
#tFile = tarfile.open("files1.tar", 'w')
for i in src:
name=os.path.join(destination,i,i+".tar")
tFile = tarfile.open(name, 'w')
os.chdir(os.path.join("/home",i))
print(os.getcwd())
file_list=glob.glob("*.txt")
with concurrent.futures.ProcessPoolExecutor() as executor:
executor.map(function,file_list,tFile)
for f in tFile.getnames():
print(f)
tFile.close()
这不起作用,因为 executor.map 函数没有将 tFile 对象传递给函数。我该如何解决这个问题?