Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import multiprocessing as mpl
  2. import stocker
  3. from time import time
  4. import threading
  5. import datetime
  6.  
  7.  
  8. def fill_d(name):
  9.     return stocker.predict.tomorrow(name)[0]  # [predicted price, error(%), date of the next business day]
  10.  
  11.  
  12. def runner(name, d):
  13.     with mpl.Pool() as p:
  14.         data = p.map(fill_d, [name for _ in range(5)])
  15.         print(d, data)
  16.         tomorrow = datetime.date.today() + datetime.timedelta(days=1)
  17.         print(tomorrow, 'tomorrow')
  18.         d[name][tomorrow] = sum(data) / len(data)
  19.  
  20.  
  21. stock = ['AAPL', 'AMZN']
  22.  
  23. if __name__ == '__main__':
  24.     manager = mpl.Manager()
  25.     d = manager.dict()
  26.     threads = []
  27.     for name in stock:
  28.         d[name] = {}
  29.     for name in stock:
  30.         t = threading.Thread(target=runner, args=(name, d))
  31.         threads.append(t)
  32.         print(f'[+] Start thread {t.name}')
  33.         t.start()
  34.     t = time()
  35.     for i in threads:
  36.         i.join()
  37.     print(d)
  38.     print(time() - t)
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement