Django local development server hangs after calling pandas df.plot a second time

43 views
Skip to first unread message

asilver

unread,
Jan 7, 2018, 1:53:21 PM1/7/18
to Django users

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...

Matemática A3K

unread,
Jan 7, 2018, 2:53:45 PM1/7/18
to django...@googlegroups.com
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

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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.
For more options, visit https://groups.google.com/d/optout.

asilver

unread,
Jan 8, 2018, 12:07:42 PM1/8/18
to Django users
I looked around for a django-pandas forum/group but could not find one...   I didnt' provide any errors or stack traces because there are none... The web server just hangs and I have to go into Windows task manager and kill the cmd window and sometime even that is not enough (I need to also separately kill the python2.7 process).  Any other recommendations for troubleshooting?  I'm not really a python expert by any means...

Thx
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Matemática A3K

unread,
Jan 8, 2018, 12:15:49 PM1/8/18
to django...@googlegroups.com
On Mon, Jan 8, 2018 at 2:07 PM, asilver <asi...@net-sense.com> wrote:
I looked around for a django-pandas forum/group but could not find one...   I didnt' provide any errors or stack traces because there are none... The web server just hangs and I have to go into Windows task manager and kill the cmd window and sometime even that is not enough (I need to also separately kill the python2.7 process).  Any other recommendations for troubleshooting?  I'm not really a python expert by any means...

Thx

Sorry, but I haven't used Pandas, django-pandas and I don't use Windows, so I can't help you. Why don't you try opening an issue in https://github.com/chrisdev/django-pandas or contacting the listed contributors? I don't think they are reading this list...

HTH
 
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages