>From pep333: If the iterable returned by the application has a close()
method, the server or gateway must call that method upon completion
of the current request, whether the request was completed normally, or
terminated early due to an error.
You can write an iterator to run your task on close():
class Iterator(object):
def __iter__(self): return self
def next(self): raise StopIteration
def close(self):
# your code
And in pylons:
def action(self):
response.app_iter = iter(Iterator())
But I also think that this is a bad idea and strongly encourage you to
use a real queue system like carrot
http://pypi.python.org/pypi/carrot/0.10.4
On Mon, May 31, 2010 at 7:04 PM, Eugueny Kontsevoy <[email protected]> wrote:
> We have an unusual server application that is essentially a task queue: it
> takes job requests via HTTP and sticks them into a thread/process pool of
> workers. It works well.
>
> However, I have always felt uncomfortable having all this process/thread
> logic in our app. It looks suspiciously similar to a cluster of Pasters it
> runs on. This got me thinking: what if we just do everything "in-place"? Is
> it possible to do the following:
>
> A request comes into Pylons controller via HTTP
> The controller immediately tells the client "200 OK" - so it won't wait.
> ... and proceeds working on that request right there, synchronously -
> Paster&Nginx will take care of finding another available process/thread to
> handle the next request.
>
> This would make our code much leaner and cleaner, but I am not sure how to
> implement #2. It seems like the only way to end the request is to return
> something (or throw an exception) from the controller.
>
> Thoughs?
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.