TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Python and the Real-time Web

152 pointsby joecarpenteralmost 12 years ago

7 comments

lvhalmost 12 years ago
Nice, thorough article. Kudos for showing all the alternatives. That said, I think you had a strong preference for one, and that shone through. For example:<p>With greenlets, you say: Why is greenlets are great? Because they allow writing asynchronous code in synchronous fashion. They allow using existing, synchronous libraries asynchronously. Context switching magic is hidden by greenlet implementation.<p>Greenlets don&#x27;t magically make synchronous libraries asynchronous! That&#x27;s gevent! Greenlets are just the coroutines. Plus, you&#x27;re forgetting that &quot;magically&quot; making sync libraries async doesn&#x27;t actually work in plenty of cases, and the way that it works generally involves monkeypatching half the IO bits in the standard library!<p>Also, there&#x27;s a bit of a false dichotomy. You claim that there&#x27;s two options: coroutines or callbacks. That might be true, but then you need to keep in mind that callbacks doesn&#x27;t necessarily mean something-looking-like-the-Tornado-callback-demo-code. That mind seem like a nitpicky implementation detail, but that&#x27;s the sort of thing that lets Twisted do inlineCallbacks (where you write generators instead of coroutines) or Corotwine (a third party package where you get actual coroutines) or geventreactor (a third party package where the event loop is done by gevent -- since the other way around isn&#x27;t actually supported).<p>The inline callbacks equivalent, given the same API, would be something along the lines of:<p><pre><code> data = yield get_more_data() return make_response(data) </code></pre> The twisted equivalent of this wouldn&#x27;t even look like data = yield get_more_data(); Twisted&#x27;s API calls you when there&#x27;s data, so it looks even simpler:<p>def dataReceived(self, data): return make_response(data)<p>Also, txsockjs now integrates great with the Twisted Resource API, so it will live neatly side by side with existing web stuff you&#x27;re serving from twisted, which <i>can</i> include e.g. WSGI apps (since twisted comes with a wsgi server :))<p>I have prepared a talk that deals with Twisted Mixing, which I hope to submit to PyCon. The work in progress is here: <a href="https://chiselapp.com/user/lvh/repository/TwistedMixing/index" rel="nofollow">https:&#x2F;&#x2F;chiselapp.com&#x2F;user&#x2F;lvh&#x2F;repository&#x2F;TwistedMixing&#x2F;inde...</a><p>I&#x27;d love to have a cogent argument for the things you didn&#x27;t like about Twisted, but two out of three appear to be more or less the same thing (&quot;complex&quot;, &quot;hard to learn&quot;), and, on top of that, subjective. I&#x27;m sorry you had a hard time. It shouldn&#x27;t have been. If you have any specific issues, I would like to address them. I&#x27;m assuming that by &quot;not PEP-8&quot; you mean mostly &quot;uses camelCase&quot;, in which case I&#x27;ll give the usual apologist answer:<p>- Twisted predates PEP-8&#x27;s recommendation of snake_case ;-) - It&#x27;s actually PEP-8 compliant: the PEP says to do what the code around you does, and something about consistency being a hobgoblin ;-)<p>Also, you mention that you can run Twisted on Tornado, but not Cyclone. Is there a particular reason for that? From all points I can tell, they get you the same result (mixing Twisted and Tornado code), but the reactor that ships with Tornado just gives you fewer event loop options (and generally inferior ones).<p>Disclaimer: I&#x27;m a twisted dev. Can you tell? ;)
评论 #5938120 未加载
csensealmost 12 years ago
I like the blog post format better than a Google Hangout. When there&#x27;s a conversation, unless (or perhaps even if) it&#x27;s heavily moderated, things get lost in the noise.<p>I was really confused about the word &quot;polyfill,&quot; which the author used without explanation. Since I&#x27;ve written code to render filled polygons before (concavity is a fun corner case), I assumed this was what it was referring to, and I was really confused about how that&#x27;s even remotely relevant. Wikipedia finally straightened me out [1].<p>[1] <a href="http://en.wikipedia.org/wiki/Polyfill" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Polyfill</a>
评论 #5937443 未加载
评论 #5935290 未加载
评论 #5934834 未加载
jisaacstonealmost 12 years ago
I&#x27;m working on porting a node&#x2F;websockets game I wrote to python using the twisted websockets branch. (not integrated in core yet but fully functional so far)<p>Instead of using socketio I rewrote the client side code in pure js. It was not difficult at all, and nearly all browsers support websockets now anyway.<p>Anyway - if you&#x27;ve written a twisted server before then writing a websocket backend is trivial, and the frontend is not much more difficult. I might do a full writeup when the project is complete.
rubiquityalmost 12 years ago
Wow this is an incredible wealth of information in regards to the Real-time Web. I recommend anyone read this regardless of whether you use Python or not.
emehrkayalmost 12 years ago
I haven&#x27;t read the whole post yet, but is the author saying that a WSGI+Gevent is better at real-time than Tornado alone?
评论 #5935019 未加载
评论 #5934978 未加载
VeejayRampayalmost 12 years ago
As a Ruby programmer, I face the same sad state of affairs in Ruby frameworks unfortunately.<p>Nice writeup about all the alternative, well done.
the_cat_kittlesalmost 12 years ago
After stumbling around this problem for ~6 months, making half-solutions, this is such a great article. Thank you!!!