4 ms·
Show HN: A tiny library for managing blocking code in Tornado
- willvarfar 15y agovery 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
- willvarfar 15y agoalso might be interesting: http://williamedwardscoder.tumblr.com/post/16516763725/how-i-got-massively-faster-db-with-async-batching http://williamedwardscoder.tumblr.com/post/16516763725/how-i...
- swah 15y agoI read your blog. Do you mostly program Python these days? If so, do you miss static typing? (I'm giving http://dropwizard.codahale.com http://dropwizard.codahale.com a try).
- willvarfar 15y agoI sure do: http://williamedwardscoder.tumblr.com/post/18144725601/my-dream-programming-language http://williamedwardscoder.tumblr.com/post/18144725601/my-dr... dropwizard looks very very interesting to me right now.
- swah 15y ago(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.
- wulczer 15y agoLooks like it's similar to using deferToThread in Twisted (where you get a builtin threadpool implementation): http://twistedmatrix.com/documents/current/core/howto/threading.html http://twistedmatrix.com/documents/current/core/howto/thread...
- rabidsnail 15y agoIt 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.
- ronreiter 15y agoIf 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 15y agoIf most of your code is not asynchronous, why are you using an asynchronous server framework?
- zacharyvoase 15y agoThe 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/lib/gevent_selfpipe/__init__.py https://github.com/zacharyvoase/gevent-selfpipe/blob/master/...
- rabidsnail 15y agoHow is decorating your function with @in_thread_pool complex? The threads are managed automatically. Unless I'm misunderstanding your question.
- zacharyvoase 15y agoI'm talking about the implementation, sorry :)