librelist archives

« back to archive

Flask : How to make call-back fuction non-blocking using thread.

Flask : How to make call-back fuction non-blocking using thread.

From:
Parakrant Sarkar
Date:
2013-06-29 @ 13:00
I am using flask framework to interface a text-to-speech system to web.
Basically website takes input via textbox and returns a audio file. Once
text is entered into text box and a button is pressed below call-back will
be invoked.

def task_text2speech():

# call to my text to speech system # respond to client

In above above function step "# call to my text to speech system" will take
around 30-100 seconds. During this time client browser will not have any
response. I want to overcome this by starting a thread instead of blocking
task_text2speech in task_text2speech and once thread is done with speech
synthesis respond to client.

For me implementing threading is not a issue, but I am not aware of flask
handlers required to respond to client in above scenario. Any docs or
example implementation are appreciated.








-- 
Parakrant Sarkar
Senior Scientific Officer
School of Information Technology
IIT Kharagpur - 721302
Mobile: +919007573677,
Email: parakrantsarkar@gmail.com <Email%3Aparakrantsarkar@gmail.com>,
parakrantsarkar@sit.iitkgp.ernet.in<http://parakrantsarkar.sit.iitkgp.ernet.in>

Re: [flask] Flask : How to make call-back fuction non-blocking using thread.

From:
Anthony Ford
Date:
2013-06-29 @ 16:51
You can use a queue system such a celery ( https://www.celeryproject.org)
and and  broker such as rabbitMQ or redis.

Anthony Ford
Center for Advanced Radio Astronomy
Univ. of Texas at Brownsville

Pardon any typos. Sent from mobile device.
On Jun 29, 2013 8:00 AM, "Parakrant Sarkar" <parakrantsarkar@gmail.com>
wrote:

>
>
> I am using flask framework to interface a text-to-speech system to web.
> Basically website takes input via textbox and returns a audio file. Once
> text is entered into text box and a button is pressed below call-back will
> be invoked.
>
> def task_text2speech():
>
> # call to my text to speech system # respond to client
>
> In above above function step "# call to my text to speech system" will
> take around 30-100 seconds. During this time client browser will not have
> any response. I want to overcome this by starting a thread instead of
> blocking task_text2speech in task_text2speech and once thread is done with
> speech synthesis respond to client.
>
> For me implementing threading is not a issue, but I am not aware of flask
> handlers required to respond to client in above scenario. Any docs or
> example implementation are appreciated.
>
>
>
>
>
>
>
>
> --
> Parakrant Sarkar
> Senior Scientific Officer
> School of Information Technology
> IIT Kharagpur - 721302
> Mobile: +919007573677,
> Email: parakrantsarkar@gmail.com <Email%3Aparakrantsarkar@gmail.com>,
> parakrantsarkar@sit.iitkgp.ernet.in<http://parakrantsarkar.sit.iitkgp.ernet.in>
>
>

Re: [flask] Flask : How to make call-back fuction non-blocking using thread.

From:
Jonas Brunsgaard
Date:
2013-07-02 @ 21:39
On Sat, Jun 29, 2013 at 6:51 PM, Anthony Ford <ford.anthonyj@gmail.com>wrote:

> You can use a queue system such a celery ( https://www.celeryproject.org)
> and and  broker such as rabbitMQ or redis.
>
+1, cleary the best solution...

> Anthony Ford
> Center for Advanced Radio Astronomy
> Univ. of Texas at Brownsville
>
> Pardon any typos. Sent from mobile device.
> On Jun 29, 2013 8:00 AM, "Parakrant Sarkar" <parakrantsarkar@gmail.com>
> wrote:
>
>>
>>
>> I am using flask framework to interface a text-to-speech system to web.
>> Basically website takes input via textbox and returns a audio file. Once
>> text is entered into text box and a button is pressed below call-back will
>> be invoked.
>>
>> def task_text2speech():
>>
>> # call to my text to speech system # respond to client
>>
>> In above above function step "# call to my text to speech system" will
>> take around 30-100 seconds. During this time client browser will not have
>> any response. I want to overcome this by starting a thread instead of
>> blocking task_text2speech in task_text2speech and once thread is done with
>> speech synthesis respond to client.
>>
>> For me implementing threading is not a issue, but I am not aware of flask
>> handlers required to respond to client in above scenario. Any docs or
>> example implementation are appreciated.
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> Parakrant Sarkar
>> Senior Scientific Officer
>> School of Information Technology
>> IIT Kharagpur - 721302
>> Mobile: +919007573677,
>> Email: parakrantsarkar@gmail.com <Email%3Aparakrantsarkar@gmail.com>,
>> parakrantsarkar@sit.iitkgp.ernet.in<http://parakrantsarkar.sit.iitkgp.ernet.in>
>>
>>

Re: [flask] Flask : How to make call-back fuction non-blocking using thread.

From:
Rahul Rai
Date:
2013-07-03 @ 08:27
+1 to that. Doing so will make the process asynchronous and more scalable.

also - be careful about too many requests coming in to translate the text
to speech (which as you said takes a long time). Even if using a queue or
threads, make sure that the processes/threads which are spawned to do the
conversion are throttled by some sort of a  controller to prevent overload.


Anyways - if you are not looking at scalability of the system, then my
comments do not apply.

On 3 July 2013 03:09, Jonas Brunsgaard <jonas.brunsgaard@gmail.com> wrote:

>
>
>
> On Sat, Jun 29, 2013 at 6:51 PM, Anthony Ford <ford.anthonyj@gmail.com>wrote:
>
>> You can use a queue system such a celery ( https://www.celeryproject.org)
>> and and  broker such as rabbitMQ or redis.
>>
> +1, cleary the best solution...
>
>> Anthony Ford
>> Center for Advanced Radio Astronomy
>> Univ. of Texas at Brownsville
>>
>> Pardon any typos. Sent from mobile device.
>> On Jun 29, 2013 8:00 AM, "Parakrant Sarkar" <parakrantsarkar@gmail.com>
>> wrote:
>>
>>>
>>>
>>> I am using flask framework to interface a text-to-speech system to web.
>>> Basically website takes input via textbox and returns a audio file. Once
>>> text is entered into text box and a button is pressed below call-back will
>>> be invoked.
>>>
>>> def task_text2speech():
>>>
>>> # call to my text to speech system # respond to client
>>>
>>> In above above function step "# call to my text to speech system" will
>>> take around 30-100 seconds. During this time client browser will not have
>>> any response. I want to overcome this by starting a thread instead of
>>> blocking task_text2speech in task_text2speech and once thread is done with
>>> speech synthesis respond to client.
>>>
>>> For me implementing threading is not a issue, but I am not aware of
>>> flask handlers required to respond to client in above scenario. Any docs or
>>> example implementation are appreciated.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Parakrant Sarkar
>>> Senior Scientific Officer
>>> School of Information Technology
>>> IIT Kharagpur - 721302
>>> Mobile: +919007573677,
>>> Email: parakrantsarkar@gmail.com <Email%3Aparakrantsarkar@gmail.com>,
>>> 
parakrantsarkar@sit.iitkgp.ernet.in<http://parakrantsarkar.sit.iitkgp.ernet.in>
>>>
>>>
>