Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import multiprocessing as mpl
- import stocker
- from time import time
- import threading
- import datetime
- def fill_d(name):
- return stocker.predict.tomorrow(name)[0] # [predicted price, error(%), date of the next business day]
- def runner(name, d):
- with mpl.Pool() as p:
- data = p.map(fill_d, [name for _ in range(5)])
- print(d, data)
- tomorrow = datetime.date.today() + datetime.timedelta(days=1)
- print(tomorrow, 'tomorrow')
- d[name][tomorrow] = sum(data) / len(data)
- stock = ['AAPL', 'AMZN']
- if __name__ == '__main__':
- manager = mpl.Manager()
- d = manager.dict()
- threads = []
- for name in stock:
- d[name] = {}
- for name in stock:
- t = threading.Thread(target=runner, args=(name, d))
- threads.append(t)
- print(f'[+] Start thread {t.name}')
- t.start()
- t = time()
- for i in threads:
- i.join()
- print(d)
- print(time() - t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement