5
I’m trying to make a program that requests on a DDE server, so I need to collect the data every 0.1 sec. But with each iteration of the program the computer memory increases and at the end for 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 it 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 @Marcos suggested:
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, I’d appreciate it.
Have tried calling Garbage Collector { gc.Collect() } at the end of each iteration ?
– Felipe
I added the following line: collected = gc.Collect() print "Garbage Collector: collected %d Objects." % (collected) responds that it is with 0 objects. is now showing this error: Maximum recursion Depth exceeded in instancecheck
– Bruno Maronezzi
Use the iterative version of the algorithm ... your program is making infinite recursive calls
– Felipe
Felipe, I returned to the recursive version, but the memory continues to increase. Would have something to do in relation to this?
– Bruno Maronezzi