I'm running a flask server, with a textbox input and a while loop (in a different thread). I want to pass the input value from the textbox to the while loop.
This is the .py code: -
from flask import Flask, render_template, request
-
import thread
-
import time
-
-
app = Flask(__name__)
-
def main():
-
-
while True:
-
time.sleep(5)
-
print "var = "+str(var)
-
-
@app.route("/")
-
def index():
-
-
templateData = {
-
'var': var
-
-
}
-
return render_template('index.html', **templateData)
-
-
@app.route('/', methods=['POST'])
-
def post():
-
-
global var
-
var = 0
-
var = int(request.form['var'])
-
return str("var: " + str(var))
-
-
if __name__ == "__main__":
-
thread.start_new_thread(main, ())
-
thread.start_new_thread(post, ())
-
app.run(host='0.0.0.0', port=8083, debug=True)
-
This is the .html code: -
<!DOCTYPE html>
-
<head>
-
<title>POST</title>
-
</head>
-
<body>
-
<form method="POST">
-
var:<br>
-
<input name="var">
-
<br><br>
-
Current: {{ var }} <br><br>
-
<input type="submit">
-
</form>
-
</body>
-
</html>
-
I don't know what is the proper way to get the value to the while loop, because I'm getting mixed signals in the loop. If I for example write 3 in the textbox I'll get... -
var = 0
-
var = 3
-
var = 0
-
var = 3
-
var = 0
-
var = 3
-
var = 0
-
var = 3
-
...in the while loop, because it's first reading var = 0 and then var = int(request.for m['var'])
0 4248 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bartosz Wegrzyn |
last post by:
I use onblue event to validate fields in my form.
I do this onblur="return isname()" and so so ...
I have one form with 20 fields.
My problem is that when the focus is for example on the first field of my
form
the "name" field and I click somewher or press tab than I loose focus and my
isname() function is executed. Everything is fine but the focus was change
for next field
|
by: Gremlin |
last post by:
If you are not familiar with the halting problem, I will not go into
it in detail but it states that it is impossible to write a program
that can tell if a loop is infinite or not. This is a fallacy built
on the assumption of mythical infinite all powerfull machines. In
reality we deal with finite machines that are capable of two states in
a loop, they either terminate, or repeat themselves. In the mythical
halting problem scenario...
|
by: mailpitches |
last post by:
Hello,
Is there any way to kill a Javascript infinite loop in Safari without
force-quitting the browser?
MP
|
by: Jim P. |
last post by:
I'm having trouble returning an object from an AsyncCallback called inside a
threaded infinite loop.
I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the
data from the remote peer. I have no problem connecting the peers and
streaming Network Streams. When the incoming data is finished recieving, I
act upon it. This works great as long as all of the code is inside my form.
I want to build the networking code into a...
|
by: dmoran21 |
last post by:
Hi all, I am a mathematician and I'm trying to write a program to try
out a formula that I've derived. However, it seems that I've got an
infinite loop and I don't quite understand why. I was hoping someone
could point me in the right direction.
Code:
#include <stdio.h>
#include <math.h>
| |
by: Richard |
last post by:
Hi All,
I copied a script example from http://www.irt.org/script/640.htm into
a local .html file. I opened that file first in HTML-kit, which hung
(in an infinite loop, I think) when I previewed the example.
On the off chance that example exposed a weakness in HTML-Kit, I ran
the example in IE7, which also hung.
The example seems to start an infinite loop which the user should be
|
by: James Watt |
last post by:
can anyone tell me how to do an infinite loop in C/C++, please ?
this is not a homework question .
|
by: ahmadbaseet |
last post by:
Hello all
I am new to VB.NET. I am trying to create dynamically objects and giving them the event handles. Something like this
Dim NewTab As New TabPage
Dim NewTextBox As New TextBox
Dim NewTab2 As New TabPage
Dim b As New Button
AddHandler b.Click, AddressOf b1
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |