On Wed, Jan 09, 2013 at 09:23:57AM -0500, Ben Darnell wrote:
> On Tue, Jan 8, 2013 at 10:31 PM, mrtn <
mrtn...@gmail.com> wrote:
>
> >
> > I am aware that an async library is ideal in most cases, but in many other
> > cases, we have no choice but using blocking libraries (which may block
> > longer than merely a few ms). Hence I wonder what is the correct
> > pattern/recipe for using such libraries in Tornado 2.4+? Start a separate
> > thread?
> >
>
> Yes, when you need to do something that will block for too long, a thread
> is generally the simplest way to do it. I recommend creating a threadpool
> from concurrent.futures, submitting a function to it, and using
> future.add_done_callback and io_loop.add_callback to return control to
> tornado when it's done:
>
> thread_pool.submit(func).add_done_callback(lambda future:
> io_loop.add_callback(functools.partial(callback, future)))
>
> There will be built-in support for futures in tornado 3.0. Other
> strategies include running the blocking code in a separate service and
> talking to it over http.
>
> -Ben
>
>
> >
> > In a related question, if I am using a blocking redis library (e.g.