Prevent "out of memory" issue
This commit is contained in:
parent
d3a09ea940
commit
cb7cc14529
@ -1,9 +1,11 @@
|
||||
import datetime
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
import requests
|
||||
import yfinance
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
def thread_function(s):
|
||||
@ -20,6 +22,12 @@ def thread_function(s):
|
||||
requests.post(os.getenv("API_URL") + '/symbol', json=payload, headers={'Authorization': 'Bearer ' + token})
|
||||
|
||||
|
||||
def split(a, n):
|
||||
k, m = divmod(len(a), n)
|
||||
return (a[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n))
|
||||
|
||||
|
||||
load_dotenv()
|
||||
username = os.getenv('ADMIN_EMAIL')
|
||||
password = os.getenv('ADMIN_PASSWORD')
|
||||
|
||||
@ -27,7 +35,10 @@ token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": usern
|
||||
|
||||
response = requests.get(os.getenv("API_URL") + '/symbols', headers={'Authorization': 'Bearer ' + token}).json()['data']
|
||||
|
||||
for symbol in response:
|
||||
x = threading.Thread(target=thread_function, args=(symbol,))
|
||||
x.start()
|
||||
symbols = split(response, int(len(response) / 5))
|
||||
for symbol_list in symbols:
|
||||
for symbol in symbol_list:
|
||||
x = threading.Thread(target=thread_function, args=(symbol,))
|
||||
x.start()
|
||||
|
||||
time.sleep(10)
|
||||
|
Loading…
Reference in New Issue
Block a user