I have a list of files file_list and the function get_id that I pass into pool.map. Now I want to change the proxy for all python traffic every 300 tasks. The environment proxy I set like recommended here How to pass all Python's traffics through a http proxy?
So I think I need something like a global variable to count the finished tasks. But how I have to set theses variable?
def get_id(file_list):
with open(file_list, 'rb') as fp:
tweet = pickle.load(fp)
os.system('snscrape twitter-search "(to:'+tweet+')')
NUM_CPUS = mp.cpu_count()
def mp_handler(file_list,proxies):
pool = mp.Pool(NUM_CPUS)
pool.map(get_id, file_list)
if __name__ == "__main__":
proxies = ['111.11.111.11:1212',
'222.22.222.22:1212']
os.environ['http_proxy'] = proxies[0]
os.system("echo $http_proxy")
file_list = function that create file_list
start = time.time()
mp_handler(file_list)
end = time.time()
print(end - start)