

Show HN: A tiny library for managing blocking code in Tornado - rabidsnail
https://github.com/rabidsnail/tornado-threadpool

======
ronreiter
If you need to use this library, then you shouldn't use Tornado in general...
unless most of your code is indeed asynchronous. This technique is slower than
a webserver threadpool, so be careful.

~~~
rabidsnail
If most of your code is not asynchronous, why are you using an asynchronous
server framework?

------
wulczer
Looks like it's similar to using deferToThread in Twisted (where you get a
builtin threadpool implementation):
[http://twistedmatrix.com/documents/current/core/howto/thread...](http://twistedmatrix.com/documents/current/core/howto/threading.html)

~~~
rabidsnail
It is similar to defer.deferToThread. The main difference is that this is only
about 100 lines of code that depends only on the ioloop, as opposed to
twisted.internet.defer, which also has stuff like defer.inlineCallbacks in
there.

------
zacharyvoase
The code involved in hooking together the IO loop with the thread completion
seems pretty complex. I wrote a library a short while ago to deal with the
same problem in gevent, but I opted to use the self-pipe trick; you can see
the implementation here: [https://github.com/zacharyvoase/gevent-
selfpipe/blob/master/...](https://github.com/zacharyvoase/gevent-
selfpipe/blob/master/lib/gevent_selfpipe/__init__.py)

~~~
rabidsnail
How is decorating your function with @in_thread_pool complex? The threads are
managed automatically. Unless I'm misunderstanding your question.

~~~
zacharyvoase
I'm talking about the implementation, sorry :)

------
willvarfar
very cool, want lots more examples, especially of them calling each other

e.g. show an example http hander that makes a call to over SOAP, squirts
something into a database and returns etc

p.s. mispelled calback in code example

~~~
swah
I read your blog. Do you mostly program Python these days? If so, do you miss
static typing? (I'm giving <http://dropwizard.codahale.com> a try).

~~~
willvarfar
I sure do: [http://williamedwardscoder.tumblr.com/post/18144725601/my-
dr...](http://williamedwardscoder.tumblr.com/post/18144725601/my-dream-
programming-language)

dropwizard looks very very interesting to me right now.

~~~
swah
(I've seen that entry, I agree but its probably very hard to do it).

To me as well, I even started building my service.

But after programming some Python/Clojure, one feels kinda silly when having
to write code like

    
    
        getId 
        getName
        getAge
    

for all DB columns - since in the dynamic languages its so easy to get a key
from a dynamically created dictionary with the database columns:

    
    
        (:age row)                     (Clojure)
    

Perhaps should just stop whining about it and just type the fucking
getters/setters.

