Twisted (software): Difference between revisions
→See also: removing irrelevant/non-notable 'untwisted' |
|||
Line 72: | Line 72: | ||
* [[Node.js]], an event-driven I/O framework for the [[V8 JavaScript engine]]. |
* [[Node.js]], an event-driven I/O framework for the [[V8 JavaScript engine]]. |
||
* EventMachine, an event-processing library for [[Ruby (programming language)|Ruby]].<ref>{{cite web |url=http://rubyeventmachine.com/ |title=EventMachine |accessdate=20 August 2011}}</ref> |
* EventMachine, an event-processing library for [[Ruby (programming language)|Ruby]].<ref>{{cite web |url=http://rubyeventmachine.com/ |title=EventMachine |accessdate=20 August 2011}}</ref> |
||
* Untwisted, a fork of Twisted with extended functionality and a greater emphasis on code-elegance. |
|||
* Kivy, a multi-platform GUI framework (including IOS and Android) <ref>http://kivy.org/docs/guide/other-frameworks.html</ref> |
* Kivy, a multi-platform GUI framework (including IOS and Android) <ref>http://kivy.org/docs/guide/other-frameworks.html</ref> |
||
Revision as of 20:51, 17 May 2012
Original author(s) | Glyph Lefkowitz |
---|---|
Developer(s) | Community |
Initial release | October 22, 2002[1] |
Stable release | 12.0.0
/ 11 February 2012[2] |
Repository | |
Written in | Python |
Type | Event-driven networking |
License | MIT License |
Website | twistedmatrix |
Twisted is an event-driven network programming framework written in Python and licensed under the MIT License.
Twisted projects variously support TCP, UDP, SSL/TLS, IP Multicast, Unix domain sockets, a large number of protocols (including HTTP, XMPP, NNTP, IMAP, SSH, IRC, FTP, and others), and much more. Twisted is based on the event-driven programming paradigm, which means that users of Twisted write short callbacks which are called by the framework.
Core ideas
Separation of protocols and transports
Twisted is designed for complete separation between logical protocols (usually relying on stream-based connection semantics, such as HTTP or POP3) and physical transport layers supporting such stream-based semantics (such as files, sockets or SSL libraries). Connection between a logical protocol and a transport layer happens at the last possible moment—just before information is passed into the logical protocol instance. The logical protocol is informed of the transport layer instance, and can use it to send messages back and to check for the peer's identity. Note that it is still possible, in protocol code, to deeply query the transport layer on transport issues (such as checking a client-side SSL certificate). Naturally, such protocol code will fail (raise an exception) if the transport layer does not support such semantics.
Deferreds
Central to the Twisted application model is the concept of a deferred (elsewhere called a future). A deferred is a value which has not been computed yet, for example because it needs data from a remote peer. Deferreds can be passed around, just like regular objects, but cannot be asked for their value. Each deferred supports a callback chain. When the deferred gets the value, it is transferred through the callback chain, with the result of each callback being the input for the next one. This allows operating on the values of a deferred without knowing what they are. For example, if a deferred returns a string from a remote peer containing an IP address in quad format, a callback can be attached to translate it into a 32-bit number. Any user of the deferred can now treat it as a deferred returning a 32-bit number. This, and the related ability to define "errbacks" (callbacks which are called as error handlers), allows code which looks as though it is serial, while still maintaining the event-driven abstraction.
Thread support
Twisted supports an abstraction over raw threads—using a thread as a deferred source. Thus, a deferred is returned immediately, which will receive a value when the thread finishes. Callbacks can be attached which will run in the main thread, thus alleviating the need for complex locking solutions. A prime example of such usage, which comes from Twisted's support libraries, is using this model to call into databases. The database call itself happens on a foreign thread, but the analysis of the result happens in the main thread.
Foreign loop support
Twisted can integrate with foreign event loops, such as those of GTK+, Qt and Cocoa (through PyObjC). This allows using Twisted as the networking support layer in graphical user interface (GUI) programs, using all of its libraries without adding a thread-per-socket overhead, as using Python's native library would. A full-fledged web server can be integrated in-process with a GUI program using this model, for example.
Applications using Twisted
The BuildBot continuous-integration system relies on Twisted for client/server communication[3].
ITA Software has developed an airline-reservation system for Air Canada that uses Twisted extensively[4].
Sage, an open-source alternative to Mathematica, Maple, Magma, Matlab, has a web-based interface, Sage notebook[5], that runs on a Twisted server.[6]
Twisted was used in the Omegle one-on-one chat service[7] until it was replaced with gevent for performance reasons.[8]
The Apple Calendar Server uses Twisted,[9] as do some internal projects of NASA.
The original version of social networking and microblogging site Jaiku used Twisted.
FluidDB, an online cloud data-store, uses Twisted extensively for internal RPC (partly in combination with Thrift and AMQP), for its internal services, and for external APIs.
The file-hosting service Ubuntu One uses Twisted.
Cloudkick, a cloud-server management web-application, used Twisted. It now has been rewritten using Node.js.
Twilio, a cloud telephony provider uses Twisted.
The site http://twistedmatrix.com/trac/wiki/SuccessStories lists some users of Twisted.
See also
- Perl Object Environment, a comparable framework for the Perl programming language
- JBoss Netty, for the Java programming language
- Node.js, an event-driven I/O framework for the V8 JavaScript engine.
- EventMachine, an event-processing library for Ruby.[10]
- Kivy, a multi-platform GUI framework (including IOS and Android) [11]
References
- ^ Shtull-Trauring, Itamar (2002-10-22). "Twisted 1.0". twisted-python (Mailing list). Retrieved 2008-08-14.
{{cite mailing list}}
: Unknown parameter|mailinglist=
ignored (|mailing-list=
suggested) (help) - ^ Hervé, Thomas (2012-02-11). "Twisted 12.0.0 released". python-announce (Mailing list). Retrieved 2012-02-12.
{{cite mailing list}}
: Unknown parameter|mailinglist=
ignored (|mailing-list=
suggested) (help) - ^ BuildBot Manual
- ^ Page 2 - Python Slithers into Systems
- ^ Sage_(mathematics_software)#Features
- ^ Sage a Basic Overview
- ^ Official Omegle Blog
- ^ Gevent Google Group
- ^ Darwin Calendar Server Official Site
- ^ "EventMachine". Retrieved 20 August 2011.
- ^ http://kivy.org/docs/guide/other-frameworks.html