Issue
I am trying to make for each item in my list a separate thread.
How can i achieve this?
List contains 10-20 urls. Which i need to download,parse and insert to DB
So what i am trying to do:
urls = {'url1,url2,url3'}
def get_and_insert(xml):
try:
get = requests.get(xml)
parsed = xmltodict.parse(get.text)
//upload info to DB and so on..
for each in urls:
threading.Thread(target=get_and_insert(each)).start()
But python still going one by one each url. without threading.
How to do it? Or maybe someone can share an example with async.
Solution
Problem was in
threading.Thread(target=get_and_insert(each)).start()
I pass argument to thread incorrectly
Correct way to do it:
threading.Thread(target=get_and_insert,args=(each,)).start()
Since args should get tuple
Now it works
Answered By - Kappa
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.