Took me a very long time to figure out what the problem was, and now I don't know how to solve it.
I'm using pythonanywhere to run my web.py server
So here's the problem. The web.py instance does not stop running between server requests.
Let me demonstrate what heppens because of that.
I have a list that gets populated in a loop with list.append(number)
So during the first request to the server the script runs fine.
list = (1, 2, 3)
However, since the web.py instance does not cease, on the second request to the server list ends up being (1, 2, 3, 1, 2, 3) and my script doesn't work.
How do I know web.py doesn't stop running between requests? When I deleted every namespace at the end of the scripts life, the second request to the server returned an error saying that 'web was not defined'
class web_serve:
def GET(self):
data_obj = volumePit_google()
plotter = volumePit_plot()
data_obj.download('SPY', 2)
data_obj.organize()
price, volume = zip(*data_obj.data_final)
plot_edges = data_obj.plotter_edges
e_test = data_obj.data_ticks
plotter.maxmin(price)
data_obj.plotter_ticks()
for i, tick in enumerate(data_obj.data_ticks[1:]):
edges = [data_obj.data_ticks[i], tick]
volume_edges = [plot_edges[i], plot_edges[i+1]]
day_data = data_obj.data_final[edges[0]:edges[1]]
price, volume = zip(*day_data)
plotter.dividers(volume_edges)
price_position = data_obj.price_action(price, [volume_edges[0], volume_edges[1]])
plotter.subplot.plot(price_position, price, color='g', ls='-', lw='1')
histogram = data_obj.histogram(day_data, 0)
plotter.volume_profile(histogram, volume_edges)
plotter.ticks([data_obj.plotter_edges, data_obj.dates, data_obj.plotter_tick_pos])
data_stream = cStringIO.StringIO()
plt.savefig(data_stream, bbox_inches='tight')
data_stream.seek(0)
return_png = base64.b64encode(data_stream.read())
data_stream.close()
return return_png
The variables that need clearing are within data_obj
I don't know if it's worth mentioning but both of the below classes are defined in the same file
data_obj = volumePit_google()
plotter = volumePit_plot()
class volumePit_google:
data = []
data_final = []
day_volume = []
data_ticks = [] #list contains indexes of the data_final separating days
dates = []
plotter_tick_pos = []
plotter_edges = [0]
def download(self, ticker, period):