librelist archives

« back to archive

Some actions after response sent

Some actions after response sent

From:
Aleksandr Dezhin
Date:
2012-07-31 @ 23:19
Hello,

How can I do some actions after response sent to client? I tried 
teardown_request, but it is performed before sending the response.

Let me explain why I need it. I am developing a web interface for the 
SANE (http://sane-project.org). When scanning images, the following occurs:

 1. Scanner initializes
 2. The carriage moves forward and scans image
 3. Carriage moves back to its original position

Steps 2 and 3 are time consuming(10 sec), but the final image can be 
sent to the client after 2without having to wait 3.

So I want to run 3 after sending the response to the client.

Thanks!

Re: [flask] Some actions after response sent

From:
Jonathan Haddad
Date:
2012-08-01 @ 00:11
You might want to consider using a task queue like celery for this.
http://celeryproject.org/

On Tue, Jul 31, 2012 at 4:19 PM, Aleksandr Dezhin <a.dezhin@c-e.ru> wrote:

>  Hello,
>
> How can I do some actions after response sent to client? I tried
> teardown_request, but it is performed before sending the response.
>
> Let me explain why I need it. I am developing a web interface for the SANE
> (http://sane-project.org). When scanning images, the following occurs:
>
>    1. Scanner initializes
>    2. The carriage moves forward and scans image
>    3. Carriage moves back to its original position
>
> Steps 2 and 3 are time consuming (10 sec), but the final image can be sent to
> the client after 2 without having to wait 3.
>
> So I want to run 3 after sending the response to the client.
>
> Thanks!
>



-- 
Jon Haddad
http://www.rustyrazorblade.com
skype: rustyrazorblade

Re: [flask] Some actions after response sent

From:
Aleksandr Dezhin
Date:
2012-08-01 @ 00:32
I chose Flask for this project due to the small list of dependencies. 
Using celery lead to a lot of dependencies. Furthermore, SANE requires 
to call function that makes 3 occurred in the same thread.

On 08/01/2012 04:11 AM, Jonathan Haddad wrote:
> You might want to consider using a task queue like celery for this. 
> http://celeryproject.org/
>
> On Tue, Jul 31, 2012 at 4:19 PM, Aleksandr Dezhin <a.dezhin@c-e.ru 
> <mailto:a.dezhin@c-e.ru>> wrote:
>
>     Hello,
>
>     How can I do some actions after response sent to client? I tried
>     teardown_request, but it is performed before sending the response.
>
>     Let me explain why I need it. I am developing a web interface for
>     the SANE (http://sane-project.org). When scanning images, the
>     following occurs:
>
>      1. Scanner initializes
>      2. The carriage moves forward and scans image
>      3. Carriage moves back to its original position
>
>     Steps 2 and 3 are time consuming(10 sec), but the final image can
>     be sent to the client after 2without having to wait 3.
>
>     So I want to run 3 after sending the response to the client.
>
>     Thanks!
>
>
>
>
> -- 
> Jon Haddad
> http://www.rustyrazorblade.com
> skype: rustyrazorblade
>

Re: [flask] Some actions after response sent

From:
Jonathan Haddad
Date:
2012-08-01 @ 01:16
If you have time consuming tasks that are being done out of the context of
the user's request, it's best to kick them to an async process.  Doing them
in flask ties up the process, and several of them could lead to your app
being unavailable.

If you don't want to use celery, you can kick off a subprocess.  Celery
works with a lot of backends - i'm not sure which dependencies you have a
problem with, celery is pretty lightweight and easy to use.

On Tue, Jul 31, 2012 at 5:32 PM, Aleksandr Dezhin <a.dezhin@c-e.ru> wrote:

>  I chose Flask for this project due to the small list of dependencies.
> Using celery lead to a lot of dependencies. Furthermore, SANE requires to
> call function that makes 3 occurred in the same thread.
>
>
> On 08/01/2012 04:11 AM, Jonathan Haddad wrote:
>
> You might want to consider using a task queue like celery for this.
> http://celeryproject.org/
>
> On Tue, Jul 31, 2012 at 4:19 PM, Aleksandr Dezhin <a.dezhin@c-e.ru> wrote:
>
>>  Hello,
>>
>> How can I do some actions after response sent to client? I tried
>> teardown_request, but it is performed before sending the response.
>>
>> Let me explain why I need it. I am developing a web interface for the SANE
>> (http://sane-project.org). When scanning images, the following occurs:
>>
>>    1. Scanner initializes
>>    2. The carriage moves forward and scans image
>>    3. Carriage moves back to its original position
>>
>> Steps 2 and 3 are time consuming (10 sec), but the final image can be
>> sent to the client after 2 without having to wait 3.
>>
>> So I want to run 3 after sending the response to the client.
>>
>> Thanks!
>>
>
>
>
>  --
> Jon Haddad
> http://www.rustyrazorblade.com
> skype: rustyrazorblade
>
>
>


-- 
Jon Haddad
http://www.rustyrazorblade.com
skype: rustyrazorblade

Re: [flask] Some actions after response sent

From:
Gabriel Jordão
Date:
2012-08-01 @ 01:46
Take a look at RQ (http://python-rq.org/). I haven't used it, but it seems
even simpler than celery and may solve your problem.

On Tue, Jul 31, 2012 at 10:16 PM, Jonathan Haddad <jon@jonhaddad.com> wrote:

> If you have time consuming tasks that are being done out of the context of
> the user's request, it's best to kick them to an async process.  Doing them
> in flask ties up the process, and several of them could lead to your app
> being unavailable.
>
> If you don't want to use celery, you can kick off a subprocess.  Celery
> works with a lot of backends - i'm not sure which dependencies you have a
> problem with, celery is pretty lightweight and easy to use.
>
> On Tue, Jul 31, 2012 at 5:32 PM, Aleksandr Dezhin <a.dezhin@c-e.ru> wrote:
>
>>  I chose Flask for this project due to the small list of dependencies.
>> Using celery lead to a lot of dependencies. Furthermore, SANE requires to
>> call function that makes 3 occurred in the same thread.
>>
>>
>> On 08/01/2012 04:11 AM, Jonathan Haddad wrote:
>>
>> You might want to consider using a task queue like celery for this.
>> http://celeryproject.org/
>>
>> On Tue, Jul 31, 2012 at 4:19 PM, Aleksandr Dezhin <a.dezhin@c-e.ru>wrote:
>>
>>>  Hello,
>>>
>>> How can I do some actions after response sent to client? I tried
>>> teardown_request, but it is performed before sending the response.
>>>
>>> Let me explain why I need it. I am developing a web interface for the SANE
>>> (http://sane-project.org). When scanning images, the following occurs:
>>>
>>>    1. Scanner initializes
>>>    2. The carriage moves forward and scans image
>>>    3. Carriage moves back to its original position
>>>
>>> Steps 2 and 3 are time consuming (10 sec), but the final image can be
>>> sent to the client after 2 without having to wait 3.
>>>
>>> So I want to run 3 after sending the response to the client.
>>>
>>> Thanks!
>>>
>>
>>
>>
>>  --
>> Jon Haddad
>> http://www.rustyrazorblade.com
>> skype: rustyrazorblade
>>
>>
>>
>
>
> --
> Jon Haddad
> http://www.rustyrazorblade.com
> skype: rustyrazorblade
>
>


-- 
*
*
*Gabriel Jordão*

T (71) 3494-3514
C (71) 8780-0519
gabrielpjordao@jusbrasil.com.br
www.jusbrasil.com.br

Re: [flask] Some actions after response sent

From:
Shriram Kunchanapalli
Date:
2012-08-01 @ 02:03
Hello Gabriel,

Thanks for pointing out rq.
Has anyone tried it on Windows ?

Shriram

On Wed, Aug 1, 2012 at 7:16 AM, Gabriel Jordão <
gabrielpjordao@jusbrasil.com.br> wrote:

> Take a look at RQ (http://python-rq.org/). I haven't used it, but it
> seems even simpler than celery and may solve your problem.
>
>
> On Tue, Jul 31, 2012 at 10:16 PM, Jonathan Haddad <jon@jonhaddad.com>wrote:
>
>> If you have time consuming tasks that are being done out of the context
>> of the user's request, it's best to kick them to an async process.  Doing
>> them in flask ties up the process, and several of them could lead to your
>> app being unavailable.
>>
>> If you don't want to use celery, you can kick off a subprocess.  Celery
>> works with a lot of backends - i'm not sure which dependencies you have a
>> problem with, celery is pretty lightweight and easy to use.
>>
>> On Tue, Jul 31, 2012 at 5:32 PM, Aleksandr Dezhin <a.dezhin@c-e.ru>wrote:
>>
>>>  I chose Flask for this project due to the small list of dependencies.
>>> Using celery lead to a lot of dependencies. Furthermore, SANE requires
>>> to call function that makes 3 occurred in the same thread.
>>>
>>>
>>> On 08/01/2012 04:11 AM, Jonathan Haddad wrote:
>>>
>>> You might want to consider using a task queue like celery for this.
>>> http://celeryproject.org/
>>>
>>> On Tue, Jul 31, 2012 at 4:19 PM, Aleksandr Dezhin <a.dezhin@c-e.ru>wrote:
>>>
>>>>  Hello,
>>>>
>>>> How can I do some actions after response sent to client? I tried
>>>> teardown_request, but it is performed before sending the response.
>>>>
>>>> Let me explain why I need it. I am developing a web interface for the SANE
>>>> (http://sane-project.org). When scanning images, the following occurs:
>>>>
>>>>    1. Scanner initializes
>>>>    2. The carriage moves forward and scans image
>>>>    3. Carriage moves back to its original position
>>>>
>>>> Steps 2 and 3 are time consuming (10 sec), but the final image can be
>>>> sent to the client after 2 without having to wait 3.
>>>>
>>>> So I want to run 3 after sending the response to the client.
>>>>
>>>> Thanks!
>>>>
>>>
>>>
>>>
>>>  --
>>> Jon Haddad
>>> http://www.rustyrazorblade.com
>>> skype: rustyrazorblade
>>>
>>>
>>>
>>
>>
>> --
>> Jon Haddad
>> http://www.rustyrazorblade.com
>> skype: rustyrazorblade
>>
>>
>
>
> --
> *
> *
> *Gabriel Jordão*
>
> T (71) 3494-3514
> C (71) 8780-0519
> gabrielpjordao@jusbrasil.com.br
> www.jusbrasil.com.br
>
>

Re: [flask] Some actions after response sent

From:
Joe Esposito
Date:
2012-08-01 @ 04:16
I tried it on Windows. Unfortunately doesn't work due to the dependency on
'signal' in the timeouts.py module. Looks like an amazing tool otherwise.

On Tue, Jul 31, 2012 at 10:03 PM, Shriram Kunchanapalli <
kshriram18@gmail.com> wrote:

> Hello Gabriel,
>
> Thanks for pointing out rq.
> Has anyone tried it on Windows ?
>
> Shriram
>
> On Wed, Aug 1, 2012 at 7:16 AM, Gabriel Jordão <
> gabrielpjordao@jusbrasil.com.br> wrote:
>
>> Take a look at RQ (http://python-rq.org/). I haven't used it, but it
>> seems even simpler than celery and may solve your problem.
>>
>>
>> On Tue, Jul 31, 2012 at 10:16 PM, Jonathan Haddad <jon@jonhaddad.com>wrote:
>>
>>> If you have time consuming tasks that are being done out of the context
>>> of the user's request, it's best to kick them to an async process.  Doing
>>> them in flask ties up the process, and several of them could lead to your
>>> app being unavailable.
>>>
>>> If you don't want to use celery, you can kick off a subprocess.  Celery
>>> works with a lot of backends - i'm not sure which dependencies you have a
>>> problem with, celery is pretty lightweight and easy to use.
>>>
>>> On Tue, Jul 31, 2012 at 5:32 PM, Aleksandr Dezhin <a.dezhin@c-e.ru>wrote:
>>>
>>>>  I chose Flask for this project due to the small list of dependencies.
>>>> Using celery lead to a lot of dependencies. Furthermore, SANE requires
>>>> to call function that makes 3 occurred in the same thread.
>>>>
>>>>
>>>> On 08/01/2012 04:11 AM, Jonathan Haddad wrote:
>>>>
>>>> You might want to consider using a task queue like celery for this.
>>>> http://celeryproject.org/
>>>>
>>>> On Tue, Jul 31, 2012 at 4:19 PM, Aleksandr Dezhin <a.dezhin@c-e.ru>wrote:
>>>>
>>>>>  Hello,
>>>>>
>>>>> How can I do some actions after response sent to client? I tried
>>>>> teardown_request, but it is performed before sending the response.
>>>>>
>>>>> Let me explain why I need it. I am developing a web interface for the SANE
>>>>> (http://sane-project.org). When scanning images, the following occurs:
>>>>>
>>>>>    1. Scanner initializes
>>>>>    2. The carriage moves forward and scans image
>>>>>    3. Carriage moves back to its original position
>>>>>
>>>>> Steps 2 and 3 are time consuming (10 sec), but the final image can be
>>>>> sent to the client after 2 without having to wait 3.
>>>>>
>>>>> So I want to run 3 after sending the response to the client.
>>>>>
>>>>> Thanks!
>>>>>
>>>>
>>>>
>>>>
>>>>  --
>>>> Jon Haddad
>>>> http://www.rustyrazorblade.com
>>>> skype: rustyrazorblade
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Jon Haddad
>>> http://www.rustyrazorblade.com
>>> skype: rustyrazorblade
>>>
>>>
>>
>>
>> --
>> *
>> *
>> *Gabriel Jordão*
>>
>> T (71) 3494-3514
>> C (71) 8780-0519
>> gabrielpjordao@jusbrasil.com.br
>> www.jusbrasil.com.br
>>
>>
>

Re: [flask] Some actions after response sent

From:
Mark Steve Samson
Date:
2012-08-01 @ 01:10
Have you tried gevent?

-- 
Steve


On Wednesday, August 1, 2012 at 8:32 AM, Aleksandr Dezhin wrote:

> I chose Flask for this project due to the small list of dependencies. 
Using celery lead to a lot of dependencies. Furthermore, SANE requires to 
call function that makes 3 occurred in the same thread.
> 
> On 08/01/2012 04:11 AM, Jonathan Haddad wrote:
> > You might want to consider using a task queue like celery for this.  
http://celeryproject.org/
> > 
> > On Tue, Jul 31, 2012 at 4:19 PM, Aleksandr Dezhin <a.dezhin@c-e.ru 
(mailto:a.dezhin@c-e.ru)> wrote:
> > > Hello,
> > > 
> > > How can I do some actions after response sent to client? I tried 
teardown_request, but it is performed before sending the response.
> > > 
> > > Let me explain why I need it. I am developing a web interface for 
the SANE (http://sane-project.org). When scanning images, the following 
occurs:
> > > Scanner initializes 
> > > The carriage moves forward and scans image
> > > Carriage moves back to its original position
> > > 
> > > Steps 2 and 3 are time consuming (10 sec), but the final image can 
be sent to the client after 2 without having to wait 3.
> > > 
> > > So I want to run 3 after sending the response to the client.
> > > 
> > > Thanks!
> > 
> > 
> > 
> > -- 
> > Jon Haddad
> > http://www.rustyrazorblade.com
> > skype: rustyrazorblade 
>