Twisted有什么酷? [英] What's so cool about Twisted?

查看:140
本文介绍了Twisted有什么酷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我越来越多地听说Python的 Twisted 框架岩石和其他框架比较起来很苍白。

I'm increasingly hearing that Python's Twisted framework rocks and other frameworks pale in comparison.

任何人都可以对此进行一些说明,并可能将Twisted与其他网络编程框架进行比较。

Can anybody shed some light on this and possibly compare Twisted with other network programming frameworks.

推荐答案

Twisted有很多不同的方面,你可能会发现很酷。

There are a lot of different aspects of Twisted that you might find cool.

Twisted包含许多协议实现,意味着更多的可能性可用于与某些远程系统(在大多数情况下为客户端或服务器)通信的API - 无论是 HTTP FTP SMTP,POP3,IMAP4 DNS IRC,MSN,OSCAR,XMPP / Jabber telnet,SSH , SSL, NNTP 真的模糊协议之一,例如Finger或ident,或一个的低级协议构建协议,如 DJB netstrings 简单的面向线路的协议,或者甚至是Twisted的自定义协议之一,例如透视代理(PB)异步消息传递协议(AMP)

Twisted includes lots and lots of protocol implementations, meaning that more likely than not there will be an API you can use to talk to some remote system (either client or server in most cases) - be it HTTP, FTP, SMTP, POP3, IMAP4, DNS, IRC, MSN, OSCAR, XMPP/Jabber, telnet, SSH, SSL, NNTP, or one of the really obscure protocols like Finger, or ident, or one of the lower level protocol-building-protocols like DJB's netstrings, simple line-oriented protocols, or even one of Twisted's custom protocols like Perspective Broker (PB) or Asynchronous Messaging Protocol (AMP).

Twisted的另一个很酷的事情是,在这些低级协议实现之上,你经常会发现一个更容易使用的抽象。例如,在编写HTTP服务器时,Twisted Web提供资源抽象

Another cool thing about Twisted is that on top of these low-level protocol implementations, you'll often find an abstraction that's somewhat easier to use. For example, when writing an HTTP server, Twisted Web provides a "Resource" abstraction which lets you construct URL hierarchies out of Python objects to define how requests will be responded to.

所有这些都与合作API绑定在一起,这主要是由于事实这些功能都不是通过在网络上阻止来实现的,因此您不需要为每个操作启动线程做。这有助于人们经常归因于Twisted的可扩展性(虽然它是那种可扩展性,只涉及单个计算机,而不是那种可扩展性,让您的应用程序增长使用整个主机集群),因为Twisted可以处理数千

All of this is tied together with cooperating APIs, mainly due to the fact that none of this functionality is implemented by blocking on the network, so you don't need to start a thread for every operation you want to do. This contributes to the scalability that people often attribute to Twisted (although it is the kind of scalability that only involves a single computer, not the kind of scalability that lets your application grow to use a whole cluster of hosts) because Twisted can handle thousands of connections in a single thread, which tends to work better than having thousands of threads, each for a single connection.

避免线程对于测试和调试也是有益的(因此,对于一个线程来说,可靠性)。由于在典型的基于Twisted的程序中没有优先的上下文切换,因此您通常不需要担心锁定。通过模拟这些网络事件,可以轻松地对依赖于不同网络事件发生顺序的竞争条件进行单元测试(而模拟上下文切换不是大多数(任何?)线程库提供的功能)。

Avoiding threading is also beneficial for testing and debugging (and hence reliability in general). Since there is no pre-emptive context switching in a typical Twisted-based program, you generally don't need to worry about locking. Race conditions that depend on the order of different network events happening can easily be unit tested by simulating those network events (whereas simulating a context switch isn't a feature provided by most (any?) threading libraries).

Twisted也是真的,真的关注质量。因此,您会在Twisted版本中很少找到回归,并且大多数API只是工作,即使您不是以常见的方式使用它们(因为我们试图测试所有可能使用它们的方法,而不仅仅是常见的方法)。对于在过去3或4年内添加到Twisted(或修改)的所有代码尤其如此,因为自那时以来,100%的行覆盖已经是最低测试要求。

Twisted is also really, really concerned with quality. So you'll rarely find regressions in a Twisted release, and most of the APIs just work, even if you aren't using them in the common way (because we try to test all the ways you might use them, not just the common way). This is particularly true for all of the code added to Twisted (or modified) in the last 3 or 4 years, since 100% line coverage has been a minimum testing requirement since then.

Twisted的另一个经常被忽视的强项是它十年来找出不同的平台怪癖。在不同的平台上有很多无证的套接字错误,很难知道它们甚至存在,更不用说处理它们了。 Twisted已经逐渐涵盖越来越多的这些,并且在这一点上它是相当好的。年轻的项目没有这种经验,所以他们错过了晦涩的失败模式,可能只会发生在你发布的任何项目的用户,而不是你。

Another often overlooked strength of Twisted is its ten years of figuring out different platform quirks. There are lots of undocumented socket errors on different platforms and it's really hard to learn that they even exist, let alone handle them. Twisted has gradually covered more and more of these, and it's pretty good about it at this point. Younger projects don't have this experience, so they miss obscure failure modes that will probably only happen to users of any project you release, not to you.

,我发现最酷的Twisted是,这是一个相当无聊的图书馆,让我忽略了很多真正无聊的问题,只关注有趣和有趣的事情。 :)

All that say, what I find coolest about Twisted is that it's a pretty boring library that lets me ignore a lot of really boring problems and just focus on the interesting and fun things. :)

这篇关于Twisted有什么酷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆