扭曲有好处吗?

发布于 2024-09-04 05:20:19 字数 1432 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼趣 2024-09-11 05:20:19

我坚持我在 Python 简述(第二版,第 540 页) ):

Twisted 包括强大的、高水平的
组件,例如网络服务器、用户
身份验证系统、邮件服务器
和客户端、即时消息、SSH
客户端和服务器、DNS 服务器和
客户端等等,以及
较低级别的基础设施
所有这些高级组件都是
建造的。每个组件都高度
可扩展且易于定制,并且
全部集成以实现互操作
顺利。这是对力量的致敬
Python 的独创性
Twisted 的开发人员可以做到这么多
在两兆字节内完成'
值得下载。

问这个极其丰富和强大的框架是否比“简单的插座”“更容易使用”有点像问汽车是否比螺丝“更容易使用”:这是一个多么奇怪的问题!

汽车是用螺丝(以及其他东西)制造的,并且不可能那么“易于使用”——仅仅因为一颗螺丝的作用如此之小,而汽车的作用却如此之大。

但如果你想从 A 地到达 B 地(并且可能携带乘客、行李、宠物……),一颗螺丝就没有多大帮助(除非你基本上要从头开始制造一辆汽车;-)。

当然,汽车并不是从 A 点到 B 点的唯一方式,就像twisted 并不是用 Python 构建以网络为中心的系统的唯一方式一样。马和马车(如 asyncore)很古雅,有趣,但不太实用;高速列车(如龙卷风)可能更容易使用,至少同样快,但灵活性要差得多;对于各种特殊用途,您可能更喜欢各种其他交通工具,从独轮车到游轮(例如,在 Python 中和用于网络的各种其他包,来自 paramikodnspython) - 所有这些都将包括螺钉作为其组件的一部分(例如,所有螺钉都将包括插座作为其构建方式的一部分),没有一个像“简单插座”那样易于使用,每个(在其自己的适用范围内)都会做很多事情比“简单套接字”本身更适合您。

在很多情况下,Twisted 都是一个很好的选择,当您需要集成多个方面的功能和/或实现一些没有完整打包解决方案的协议时,通常是最好的选择。 “简单套接字”不是——它们只是一个低级组件,可以构建更高功能、更高级别的组件,并且很少有充分的理由(当然除了学习)“推出自己的套接字” “在插座上“从头开始”构建更高级别的组件(而不是选择强大的、精心构建的现有组件)——就像你很少有理由用晶体管、电阻器、电容器等构建自己的计算机一样,而不是选择合适的集成电路;-)。

I stand by what I wrote in Python in a Nutshell (2nd edition p. 540):

Twisted includes powerful, high-level
components such as web servers, user
authentication systems, mail servers
and clients, instant messaging, SSH
clients and servers, a DNS server and
client, and so on, as well as the
lower-level infrastructure on which
all these high-level components are
built. Each component is highly
scalable and easily customizable, and
all are integrated to interoperate
smoothly. It's a tribute to the power
of Python and to the ingenuity of
Twisted's developers that so much can
be accomplished within two megabytes'
worth of download.

Asking whether this incredibly rich and powerful framework is "simpler to use" than "simple sockets" is a bit like asking if a car is "simpler to use" than a screw: what a weird question!

Cars are built with screws (among other things), and can't be quite as "simple to use" -- just because a screw does so little, a car does so much.

But if you want to get from A to B (and possibly carry passengers, luggage, pets, ...) a screw won't help much (unless you're basically going to build a car from scratch;-).

Of course cars aren't the only way to get from A to B, just as twisted is not the only way to build network-centric systems in Python. A horse and buggy (like asyncore) is quaint and fun, though less practical; a high-speed train (like tornado) may be easier to use and at least as fast, though much less flexible; and for various specialized purposes you may prefer all kinds of other conveyances, from unicycles to cruise ships (like, in Python and for networking, all kinds of other packages, from paramiko to dnspython) -- all of them will include screws as part of their components (like, all will include sockets as part of the way they're built), none will be as easy to use as "simple sockets", each (in its own range of applicability) will do a lot more for you than "simple sockets" on their own possibly could.

Twisted is an excellent choice in a vast number of cases, often the best when you need to integrate multiple aspects of functionality and/or implement some protocol for which there is no fully packaged solution. "Simple sockets" are not -- they're just a low-level component out of which higher-functionality, higher-level ones are built, and there rarely is a good reason (except learning, of course) to "roll your own" higher level components built "from scratch" on top of sockets (rather than picking powerful, well-built existing ones) -- just like you'd rarely be justified in building your own computer out of transistors, resistors, capacitors, etc, rather than picking appropriate integrated circuits;-).

揽清风入怀 2024-09-11 05:20:19

Twisted 是一个并发框架。它允许您在一个应用程序中处理多个任务,而无需使用线程/进程。它使用事件驱动的异步系统来完成此操作,并且特别适合网络应用程序。异步代码通常与正常代码有些“不同”,因为流程不明确并且事情基于外部事件发生。这可能会令人困惑,但它确实有效。 Twisted 可以说是最成熟的 Python 异步并发库,因此如果您打算这样做,那么 Twisted 是值得押注的好东西。

正如您所说,“简单套接字”是通信原语,不能与twisted相媲美。你想做什么?

Twisted is a concurrency framework. It allows you to juggle multiple tasks in one application without using threads/processes. It does this using an event driven asynchronous system and is especially good with networking applications. Asynchronous code generally tends to be a little 'different' from normal stuff since the flow is not explicit and things happen based on external events. This can be confusing but it works. Twisted is arguably the most mature Python async concurrency library so if that's what you're planning to do, twisted is a good thing to bet on.

"Simple sockets" as you put them are communication primitives and not really comparable to twisted. What are you trying to do?

旧城烟雨 2024-09-11 05:20:19

我想说这很好。只需查看此页使用twisted 的项目即可。

I'd say it's good. Just look at this page of projects using twisted.

春风十里 2024-09-11 05:20:19

Twisted 于 2002 年首次发布,此后规模不断壮大。 (这是一个敏感的话题,很多人会认为这在框架中是好的和必要的) - 然而对于现在正在接触该项目的人来说,这可能有点令人畏惧。但是,如果您正在推动异步框架,那么还有一些选择。我发现这个博客很有趣: http://nichol.as/asynchronous-servers-in-蟒蛇。除了基准之外,仅比较代码示例就非常有趣。

Twisted was first released in 2002 and has bloated substantially since then; (this is a touchy subject and many people would argue that this is good and necessary in a framework) - However for someone approaching the project now it can be a bit daunting. There are options however if you're pushing towards asynchronous frameworks. I found this blog to be interesting: http://nichol.as/asynchronous-servers-in-python. Benchmarks aside, the code samples alone are quite interesting to compare.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文