Python 在多处理期间追加到列表

Python 在多处理期间追加到列表,python,Python,在我不断更新列表的同时,我想检查某些元素是否已经存在于某些列表中。我正在使用多处理来实现这一点,但目前我的列表每次都会重新初始化。任何关于如何在不重新初始化的情况下附加到列表的建议都会非常有用。提前感谢 import multiprocessing as mp import socket # Set the default timeout in seconds timeout = 20 socket.setdefaulttimeout(timeout) from PIL import Im

在我不断更新列表的同时,我想检查某些元素是否已经存在于某些列表中。我正在使用多处理来实现这一点,但目前我的列表每次都会重新初始化。任何关于如何在不重新初始化的情况下附加到列表的建议都会非常有用。提前感谢

import multiprocessing as mp

import socket

# Set the default timeout in seconds
timeout = 20
socket.setdefaulttimeout(timeout)

from PIL import Image 
import hashlib
import os
image_hash_list=[]
url_list =[]
some_dict=dict()
def getImages(val):
    # import pdb;pdb.set_trace()
    #Dowload images
    f = open('image_files.txt', 'a')
    try:
        url=val # preprocess the url from the input val
        local=url.split('/')[-1] #Filename Generation From Global Varables And Rand Stuffs...
        urllib.request.urlretrieve(url,local)
        md5hash = hashlib.md5(Image.open(local).tobytes())
        image_hash = md5hash.hexdigest()
        global image_hash_list
        global url_list
        if image_hash not in image_hash_list:
            image_hash_list.append(image_hash)
            some_dict[image_hash] = 0
            os.remove(local)
            f.write(url+'\n')
            return 1
        else:
            os.remove(local)
        print(some_dict.keys())
    except Exception as e:
        return 0

# if __name__ == '__main__':
files = "Identity.txt"
lst = list(open(files))
lst = [l.replace("\n", "") for l in lst]
pool = mp.Pool(processes=12)
res = pool.map(getImages, lst)
print ("tempw")

在这里,每次都会重新初始化图像\u哈希\u列表

使用
管理器
创建共享列表和目录(以及其他类型):