如何将两个整数与Twisted相加? [英] How do I add two integers together with Twisted?

查看:128
本文介绍了如何将两个整数与Twisted相加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序中有两个整数;我们将其称为 a b 。我想将它们加在一起并得到另一个整数。这些是常规的Python int 对象。我很好奇;如何将它们与Twisted一起添加?是否在某处有一个特殊的 performAsynchronousAddition 函数?我需要 Deferred 吗?那反应堆呢?

I have two integers in my program; let's call them "a" and "b". I would like to add them together and get another integer as a result. These are regular Python int objects. I'm wondering; how do I add them together with Twisted? Is there a special performAsynchronousAddition function somewhere? Do I need a Deferred? What about the reactor? Is the reactor involved?

推荐答案

好的,要明确。

Twisted对 ​​ cpu绑定任务 没有任何作用,这是有充分理由的。无法通过对子任务重新排序来使计算绑定作业更快地完成;您唯一可能做的就是添加更多的计算资源;

Twisted doesn't do anything about cpu bound tasks and for good reason. there's no way to make a compute bound job go any quicker by reordering subtasks; the only thing you could possibly do is add more compute resources; and even that wouldn't work out in python because of a subtlety of its implementation.

Twisted提供了特殊的语义和事件循环处理,以防程序变成 粘住,如果它可以控制,则在外面等待;最通常是一个进程在另一台计算机上运行,​​并通过网络连接与扭曲的进程进行通信。由于无论如何您都在等待,所以twisted为您提供了一种在此期间完成更多工作的机制。也就是说,twisted为 ​​ I / O绑定任务

Twisted offers special semantics and event loop handling in case the program would become "stuck" waiting for something outside if its control; most normally a process running on another machine and communicating with your twisted process over a network connection. Since you would be waiting anyways, twisted gives you a mechanism to get more things done in the meantime. That is to say, twisted provides concurrency for I/O Bound tasks

tl; dr:扭曲用于网络代码。其他所有东西都是普通的python。

tl;dr: twisted is for network code. Everything else is just normal python.

这篇关于如何将两个整数与Twisted相加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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