[Twisted-Python] Comparing "Stackless Python + Nonblocking Stackless Modules" with Twisted.
Today, a guy gave me an URL http://code.google.com/p/stacklessexamples/wiki/StacklessNonblockModules It's a replacement of standard python socket module. What make it different is that this module only blocks a tasklet, not an entire Python thread. With this module and stackless python, theoretically, we can build a high concurrency network application framework which has a programming style close to traditional multi-thread module. The guy who gave me that URL asked a question, "Which style is better? The Twited's event-driven style or the imaginary one?" What do you think about it? Of course, twisted is an mature framework we can trust, but doesn't the imaginary one also have pros? -- look to the things around you,the immediate world around you, if you are alive,it will mean something to you ——Paul Strand
2010/5/9 Peter Cai <newptcai@gmail.com>:
Today, a guy gave me an URL http://code.google.com/p/stacklessexamples/wiki/StacklessNonblockModules
It's a replacement of standard python socket module. What make it different is that this module only blocks a tasklet, not an entire Python thread.
Gevents does monkey patching too and work with standard cpython.
With this module and stackless python, theoretically, we can build a high concurrency network application framework which has a programming style close to traditional multi-thread module.
This works with pure-python approach, not with a database driver written in C. If you monkey-patch python threads with your tasklets, greenlets or anything else your are lost. Mix threaded model for blocking things and tasklet/greenlet model for non-blocking thing are not magic :-(
The guy who gave me that URL asked a question, "Which style is better? The Twited's event-driven style or the imaginary one?"
What do you think about it? Of course, twisted is an mature framework we can trust, but doesn't the imaginary one also have pros?
IMHO (all from here) Twisted is coherent with itself. Monkey-patched solutions pretends be coherent with threaded style, but something fails. Twisted pros: * Is not based in a thread style. Forget wich is a non-reentrant lock and a dead-lock. * If you use a twisted library you don't need think about blocking issues. If you don't use a twisted library, defer to thread. * It's mature. Monkey patched pros: * Convert a thread style application to async one don't need a full rewrite. Maybe it's not easy, but need less LOCs. * If your libraries are prue-python you don't need think, only apply a monkey-patch. * Sounds cool. Excuse my poor english, Javi
On May 9, 2010, at 11:24 AM, Peter Cai wrote:
With this module and stackless python, theoretically, we can build a high concurrency network application framework which has a programming style close to traditional multi-thread module.
The guy who gave me that URL asked a question, "Which style is better? The Twited's event-driven style or the imaginary one?"
Just to be clear, Imaginary (<http://divmod.org/trac/wiki/DivmodImaginary>) uses Twisted, not Stackless.
What do you think about it? Of course, twisted is an mature framework we can trust, but doesn't the imaginary one also have pros?
If by "the imaginary one" you mean "the one implemented by stacklesssocket"... you can have both. If you want stackless-style coroutines with the Twisted mainloop, you even have multiple options! You can use either Corotwine (<https://launchpad.net/corotwine>) or Eventlet (<http://eventlet.net/>) with its Twisted hub, which should be the default (<http://eventlet.net/doc/hubs.html#eventlet.hubs.get_default_hub>). In my opinion, Twisted's model is "better" in the sense that it is the superset of the two models: you can implement lightweight tasks on top of Twisted's networking core, but you can't implement Twisted on top of lightweight threads because of the implied potential reentrancy of every call. happy microthreading, -g
participants (3)
-
Glyph Lefkowitz -
lasizoillo -
Peter Cai