Re: executing while loop and simultaneously redirecting to new page on form submission
Peter Tsapatsaris <[email protected]> Thu, 13 Oct 2016 07:07:03 -0700 (PDT)
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <[email protected]> |
Thanks for the reply Björn - I am attempting to start a new thread in
python that redirects to the webpage, but no luck so far.
def index(self):
return open('index.html')
index.exposed = True
def ledDisplay(self, message):
if message:
def newFunc():
raise cherrypy.HTTPRedirect("thanks.html")
thread.start_new_thread(newFunc, ())
while True:
//Execute LED code on loop.
The LED code gets executed, but the redirect doesn't happen. I can get
other code within newFunc to run (like a print statement), but I can't get
it to redirect. The server throws an unhandled exception error.
Any additional advice would be greatly appreciated!
On Thursday, October 13, 2016 at 3:24:27 AM UTC-4, Björn Pedersen wrote:
>
> Hi,
>
> this is a typical use case for multi-threaded programming.
>
> Your web interface just sets a variable (protected by a mutex), and a
> background thread does the LED output.
>
> Björn
>
> Am Donnerstag, 13. Oktober 2016 07:44:03 UTC+2 schrieb Peter Tsapatsaris:
>>
>> Hello everyone,
>>
>> I've been using cherrypy on a Raspberry Pi to run a web controllable LED
>> matrix. I've run into a bit of a wall. Short version of question: Is it
>> possible to send the user to a new webpage in a function WITHOUT returning
>> or breaking? I am trying to execute code in a block below the redirect.
>>
>> Long version:
>>
>> The LED control code executes on a while loop after receiving input from
>> an an HTML form like the following:
>>
>> <form name="myform" class="rounded" action="ledDisplay" method="GET"
>> onsubmit="archive.html">
>> <input type="text" class="box" name="message" maxlength="1000"
>> placeholder="enter your message" />
>> <input type="submit">
>> </form>
>>
>> The ledDisplay function executes the while loop with the message from the
>> form. My problem is this--after submission, I would like to redirect the
>> user to a new webpage (e..g, "thanks.html"). However, when I redirect it
>> either executes BEFORE the while loop, thus preventing the LED from
>> running, or executes AFTER the while loop, i.e., never.
>>
>> Does anyone know if there is a way to get CherryPy to send the user to a
>> new webpage and then continue to execute a code block? Here is a skeleton
>> of the code I'm working with:
>>
>> class myApp:
>>
>> def index(self):
>>
>> return open('index.html')
>>
>> index.exposed = True
>>
>> def ledDisplay(self, message):
>>
>>
>> if message:
>>
>> raise cherrypy.HTTPRedirect("thanks.html") /* This prevents the loop from
>> executing. Any way to open the page and still execute the loop*/
>>
>>
>>
>> while True:
>>
>> //Execute LED code on loop.
>> Apologies if I'm being obtuse - I am new to programming.
>>
>
--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.