Python Forum
Bug that crashes the Python interpreter 3.7 on Mac OS X
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug that crashes the Python interpreter 3.7 on Mac OS X
#1
I'm pretty new to Python and am currently exploring Flask. I wanted to subclass one the Field classes to create a percentage field but when I add it to a form, it crashes my interpreter. Here's the code:

from flask_wtf import FlaskForm
from wtforms import Form, FloatField, IntegerField, BooleanField, SelectField, validators
from constants import *


class PercentField(FloatField):
    def __init__(self, *args, **kwargs):
        super(PercentField, self).__init__(validators=[validators.number_range(0, 100)], *args, **kwargs)

    def process_data(self, value):
        return value / 100


class ParameterForm(FlaskForm):
    num_iterations = IntegerField('Iterations', default=500)
    initial_im2 = FloatField('Initial IM2', default=100000)

    growth_rate = PercentField('Growth rate', default=0.0)
And here's the .html file

<!DOCTYPE html>

<title>Parameter Form</title>

{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<ul>
    {% for message in messages %}
 	<li>{{ message[1] }}</li>
{% endfor %}</ul>
{% endif %}
{% endwith %}

<form action="" method="post">
            {{ parameter_form.csrf }}
<div class="input number">
                {{ parameter_form.num_iterations.label }} {{ parameter_form.num_iterations }}</div>
<div class="input number">
                {{ parameter_form.initial_im2.label }} {{ parameter_form.initial_im2 }}</div>
<div class="input percentage">
                {{ parameter_form.growth_rate.label }} {{ parameter_form.growth_rate }}</div>
<div class="input submit">
                <input type="submit" value="Run"></div>
</form>
I only get the crash when I add the line with {{ parameter_form.growth_rate.label }} {{ parameter_form.growth_rate }}

I am probably making an obvious mistake somewhere but I have no clue what exactly.

Thanks in advance,
Stef

Some additional info:

The crash only happens when I add

I get the following error message in the terminal window:
Error:
<property object at 0x10276b048> 127.0.0.1 - - [13/Feb/2019 12:49:03] "GET / HTTP/1.1" 200 - <property object at 0x10276b048> Process finished with exit code 245
Thanks,
Stef

Oversight. So, the bug happens when I add {{ parameter_form.growth_rate }}
So the object is created but things go awry when it is rendered in the browser.

Narrowed it doen further. Apparently the error occurs as soon as I add the process_data() function to the class. Tried just returning the value, returning self and not returning anything (just writing a line of mock code).
Everything leads to a fatal crash but not right away. When I just print the value to the output window I see a couple of values (listed below) before I get a crash. So it has something to do with the WTF package it seems.

The values:
0.0
1.9
4.0
1.0
2.5
0.5
20.0
100.0
0.0
20.0
2.0
2.0
0.0
2.0
Reply
#2
Why do you think it's Python rather than Flask crashing? Do you get a stacktrace when the crash happens?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding and debugging memory error crashes with python3.10.10 Arkaik 5 2,073 Apr-18-2023, 03:22 AM
Last Post: Larz60+
  Pydroid3 app crashes on xiaomi poco F3 JMD 2 1,235 Nov-27-2022, 11:56 AM
Last Post: JMD
  Mac default python interpreter Viewpoint8455 2 910 Oct-13-2022, 06:25 AM
Last Post: perfringo
  Python Interpreter ankitdixit 4 2,695 Jun-10-2022, 12:37 PM
Last Post: katy1234
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 6,866 Mar-02-2022, 01:23 AM
Last Post: tomtom
  How to set Tab size to 4 in Python interpreter? zzzhhh 1 1,838 Jan-18-2022, 12:11 PM
Last Post: snippsat
  readline.parse_and_bind() does not work in start-up script of Python interpreter zzzhhh 0 1,521 Jan-18-2022, 11:05 AM
Last Post: zzzhhh
  HTML file crashes program mikefirth 12 3,808 Dec-31-2021, 03:57 AM
Last Post: Pedroski55
  Scraping a Flexible Element - works at first, and then crashes JonnyB 0 1,508 Aug-14-2021, 07:25 PM
Last Post: JonnyB
  python interpreter won't import packages greenpy 1 1,970 Sep-11-2020, 07:47 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020