(python) using threads to get last value of stock market -
i'm trying last value of symbol list yahoo finance using thread in python. read thread documentary don't understand concept
#!/usr/bin/python threading import thread import urllib import re def th(ur): base = 'https://finance.yahoo.com/q?s='+ur htmlfile = urllib.urlopen(base).read() regex = '<span id="yfs_l84_[^.]*">(.+?)</span>' result = re.findall(regex,htmlfile) print result[0] symbollist = open("symbollist.txt").read().splitlines() threadlist = [] u in symbollist: t = thread(target=th,args=(u,)) t.start() threadlist.append(t) b in threadlist: b.join()
all code in function called "th" need thread safe.
if of isn't, you'll need lock around parts stop "threading" issues, example race conditions.
Comments
Post a Comment