I am trying to make an API validation from a given list of IP addresses using multiprocessing. All the processes contain the valid IPs will be stored in a shared queue. However, when I try to print the queue after the processes in the multiprocessing were executed, the final queue was empty. Could somebody show me how would I able to fix the code?
def validate(ip_address, results):
try:
response = requests.get('....API_URL....'))
if response.status_code is 200:
""" store in queue if valid """
results.put(multiprocessing.current_process())
except ConnectionError:
pass
def main():
""" ip_list is given """
results = multiprocessing.Queue()
processes = []
for ip in ip_list:
process = multiprocessing.Process(target = validate, args=(ip,results))
processes.append(process)
for p in processes:
p.start()
for p in processes:
p.join()
while results.empty() is False:
result = results.get()
final_list.append(result)
print(final_list) ### EMPTY queue
main()
EDIT1: I tried to replace results.put(multiprocessing.current_process())
with something random such as results.put("randomTEXT")
but final_list still prints empty. Also, could someone please suggest me a way to store the identity/name/id of the process that successfully requests the API?