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
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 %}
    {% 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>
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,

Some additional info:

The crash only happens when I add

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

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:
Why do you think it's Python rather than Flask crashing? Do you get a stacktrace when the crash happens?

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pydroid3 app crashes on xiaomi poco F3 JMD 2 369 Nov-27-2022, 11:56 AM
Last Post: JMD
  Mac default python interpreter Viewpoint8455 2 369 Oct-13-2022, 06:25 AM
Last Post: perfringo
  Python Interpreter ankitdixit 4 2,043 Jun-10-2022, 12:37 PM
Last Post: katy1234
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 1,945 Mar-02-2022, 01:23 AM
Last Post: tomtom
  How to set Tab size to 4 in Python interpreter? zzzhhh 1 1,082 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 817 Jan-18-2022, 11:05 AM
Last Post: zzzhhh
  HTML file crashes program mikefirth 12 2,281 Dec-31-2021, 03:57 AM
Last Post: Pedroski55
  Scraping a Flexible Element - works at first, and then crashes JonnyB 0 1,121 Aug-14-2021, 07:25 PM
Last Post: JonnyB
  python interpreter won't import packages greenpy 1 1,492 Sep-11-2020, 07:47 PM
Last Post: buran
  How could i change the python interpreter path of os.system() 12019202386 2 1,833 Sep-02-2020, 06:58 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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