Input (a.txt) contains data as:
{person1: [www.person1links1.com]}
{person2: [www.person2links1.com,www.person2links2.com]}...(36000 lines of such data)
I am interested in extracting data from the personal links of each person and my code is:
def get_bio(authr,urllist):
author_data=[]
for each in urllist:
try:
html = urllib.request.urlopen(each).read()
author_data.append(html)
except:
continue
f=open(authr+'.txt','w+')
for each in author_data:
f.write(str(each))
f.write('\n')
f.write('********************************************')
f.write('\n')
f.close()
if __name__ == '__main__':
q=mp.Queue()
processes=[]
with open('a.txt') as f:
for each in f:
q.put(each)# dictionary
while (q.qsize())!=0:
for authr,urls in q.get().items():
p=mp.Process(target=get_bio,args=(authr,urls))
processes.append(p)
p.start()
for proc in processes:
proc.join()
i am getting the following error while running this code( i have tried setting ulimit but encountering same error):
OSError: [Errno 24] Too many open files: 'personx.txt'
Traceback (most recent call last):
File "perbio_mp.py", line 88, in <module>
p.start()
File "/usr/lib/python3.5/multiprocessing/process.py", line 105, in start
self._popen = self._Popen(self)
File "/usr/lib/python3.5/multiprocessing/context.py", line 212, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/usr/lib/python3.5/multiprocessing/context.py", line 267, in _Popen
return Popen(process_obj)
File "/usr/lib/python3.5/multiprocessing/popen_fork.py", line 20, in __init__
self._launch(process_obj)
File "/usr/lib/python3.5/multiprocessing/popen_fork.py", line 66, in _launch
parent_r, child_w = os.pipe()
OSError: [Errno 24] Too many open files
Please point out where i am wrong and how can i correct this. Thanks