是构建多线程服务器的好选择吗

是构建多线程服务器的好选择吗

本文介绍了Twisted 是构建多线程服务器的好选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从数百个 pop3 电子邮件帐户中提取数据,并且我想构建一个强大的服务器来执行此操作.

I need to pull from hundreds of pop3 email accounts, and i want to build a robust server to do this.

twisted 是此类项目的不错选择吗?

Would twisted be a good choice for this type of project?

现在一个简单的原型是从单个 pop3 帐户中提取,然后它会从多个帐户中提取,但这将是一个序列化的过程.

Right now a simple prototype would be to pull from a single pop3 account, then it would pull from many but it would be a serialized process.

我想创建一个具有多个线程的服务器,以便它可以同时执行操作.

I want to create a server that has multiple threads so it can do things at the same time.

推荐答案

Twisted 是一个用 Python 编写的事件驱动的网络框架.它主要建立在异步和非阻塞特性上,最适合开发利用这些特性的网络应用程序.对于无法提供异步非阻塞 I/O 的用例,它具有线程支持.这是基于这样一个事实,即大部分时间都花在等待网络 I/O 操作上.

Twisted is an event-driven networking framework written in Python. It builds heavily on asynchronous and non-blocking features and is best conceived to develop networking applications that utilizes these. It has thread support for use cases where you can not provide for asynchronous non-blocking I/O. This is based on the fact that most of time is spent waiting in network I/O operations.

利用这一点的两种模型是线程模型,您可以在其中创建多个线程,每个线程完成单个任务或单个进程,该进程使用非阻塞 I/O 通过交错多个任务在单个进程中完成多个任务.Twisted 非常适合第二种模式.

The two model that exploits this is threading model where you create multiple threads, each accomplishing a single task or a single process that uses non-blocking I/O to accomplish multiple task in a single process by interleaving multiple tasks. Twisted is very suitable for the second model.

非阻塞模型

+--------------------------+
|task1 | wait period | comp|
+--------------------------+
       +--------------------------+
       |task2 | wait period | comp|
       +--------------------------+

您可以使用 Twisted 开发一个非常强大的服务器,它支持 POP3/IMAP.

You can develop a very robust server with Twisted and it has POP3 / IMAP support.

有一个例子说明如何构建 pop3 客户端与扭曲.

There is an example of how to build pop3 client with twisted.

这篇关于Twisted 是构建多线程服务器的好选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:02