Hi! This may be better suited for the django-pandas community, as it involves its internals. It is also very hard to debug without errors or stack traces.
HTH On Sun, Jan 7, 2018 at 3:51 PM, asilver <asil...@net-sense.com> wrote: > I'm trying to build a small website, using django, that stores network > performance data. The user will be able to use filters to retrieve the > exact data he/she wants and then have the option to graph that data. I'm > using django-pandas to convert filtered queryset to a dataframe and from > there to create a plot. Everything works fine the first time the plot > function is called. When the plot function is called a second time, the > python web server just hangs (started from python2.7.exe manage.py > runserver). > > Here is the django view function: > > > def FilteredPerformanceChartsView(request): > f = PerfvRtrOnlyFilter(request.GET, queryset=PerfvRtrOnly.objects.all()) > df = read_frame(f.qs, fieldnames=['runDate', 'deviceName', 'aggrPPS', > 'jdmVersion']) > > ################################################################# > # Let's pass the Pandas DataFrame off to a seperate function for > # further processing and to generate a chart. > # This should return an image (png or jpeg) > ################################################################# > chart = pandas_generate_chart(f.qs) > > return render(request, > 'performance_charts.html', > context={'filter': f, > 'chart': chart, > 'dataFrame': df, > }, > > ) > > > > The function *pandas_generate_chart* is where the problem is. After > performing a lot of troubleshooting, what appears to trigger the hang is > calling df.plot a second time. In other words, when the user hits the > button to generate a different chart. Until that second request to generate > a chart is submitted, the website still works perfect. You will also notice > that plt.close() is commented out below. If I uncomment that out, the > webserver will hang the first time this function is called. (Note, it will > display the chart). I've been looking into the pyplot interactive vs > non-interactive modes to see if that was the cause of the problem. From the > troubleshooting I've done, it is running in non-interactive mode. > > > def pandas_generate_chart(filtered_queryset): > > df = read_frame(filtered_queryset, fieldnames=['jdmVersion', 'hardware', > 'deviceName', 'aggrPPS']) > df = df.set_index('jdmVersion') > > # Plot > myplot = df.plot(kind='barh', figsize=(12,7), grid=True) > myplot.set_ylabel('JDM Version') > > format="png" > sio_file = StringIO() > plt.savefig(sio_file, format=format) > image = base64.b64encode(sio_file.getvalue())# plt.close() > sio_file.close() > return image > > > > Thank you for your help... > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/ed7e5391-3172-4914-bbd4-568e0f76d4f3%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/ed7e5391-3172-4914-bbd4-568e0f76d4f3%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BFDnh%2B%2Bj760gOXHpKf-MB2r58kchtEj-89ODv2SAjNtLz0rqw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.