I'm trying to make a program that makes requests on a DDE server, so I need to collect the data every 0.1 sec. But at each iteration of the program the computer's memory increases and in the end to the script.
I'm trying like this:
def requsitaDDE (y, j):
global quote
if j == 4:
time.sleep(.1)
#old_quote = quote[0]
quote = None
quote = []
return requsitaDDE(y, 0)
else:
current_quote = QUOTE_client.request(y[j])
quote.append(current_quote)
requsitaDDE(y, j + 1)
requsitaDDE(y,0)
But I've done that too:
while 1:
time.sleep(.1)
quote = []
for i in symbols:
current_quote = QUOTE_client.request(i)
quote.insert(y, current_quote)
y += 1
print quote
y = 0
Expensive,
The memory increment problem continues, now I did as suggested by @Marks:
while 1:
gc.collect()
#time.sleep(.1)
mem_usage = memory_usage(-1, interval=.2, timeout=1)
print(mem_usage)
y+= 1
print y
#if y == 20000:
# break
cur.execute("SELECT MAX(rowid) FROM winj") # use your col
linhaBd = cur.fetchone()
linhaBd[0]
if old_quote != QUOTE_client.request(symbols[0]):
for i in symbols:
current_quote = QUOTE_client.request(i)#.split("\t")
if symbols.index(i) == 0:
cur.execute('INSERT INTO winj(rowid, preco) VALUES(?, ?)' , [(linhaBd[0] + 1), current_quote])
conn.commit()
old_quote = current_quote
print current_quote
if symbols.index(i) == 1:
cur.execute('UPDATE winj SET quantidade = ? WHERE rowid = ?' , [current_quote, (linhaBd[0] + 1)])
conn.commit()
if symbols.index(i) == 2:
cur.execute('UPDATE winj SET hora = ? WHERE rowid = ?' , [current_quote, (linhaBd[0] + 1)])
conn.commit()
if symbols.index(i) == 3:
cur.execute('UPDATE winj SET data = ? WHERE rowid = ?' , [current_quote, (linhaBd[0] + 1)])
conn.commit()
If anyone has any ideas, thank you.