一個乾淨、輕量級的 Python 扭曲替代品? [關閉] - A clean, lightweight alternative to Python's twisted? [closed]

問題:

Closed. 關閉。 This question does not meet Stack Overflow guidelines . 此問題不符合Stack Overflow 準則 It is not currently accepting answers. 它目前不接受答案。

Want to improve this question?想改善這個問題嗎? Update the question so it's on-topic for Stack Overflow.更新問題,使其成爲 Stack Overflow的主題

Closed 6 years ago . 6年前關閉。

A (long) while ago I wrote a web-spider that I multithreaded to enable concurrent requests to occur at the same time.不久前,我寫了一個多線程的 web-spider,使併發請求能夠同時發生。 That was in my Python youth, in the days before I knew about the GIL and the associated woes it creates for multithreaded code (IE, most of the time stuff just ends up serialized!)...那是在我的 Python 青年時期,在我瞭解GIL以及它爲多線程代碼帶來的相關問題之前的日子裏(即,大多數情況下,東西最終都會被序列化!)...

I'd like to rework this code to make it more robust and perform better.我想重新編寫此代碼以使其更健壯並性能更好。 There are basically two ways I could do this: I could use the new multiprocessing module in 2.6+ or I could go for a reactor / event-based model of some sort.基本上有兩種方法可以做到這一點:我可以在 2.6+ 中使用新的多處理模塊,或者我可以使用某種反應器/基於事件的模型。 I would rather do the later since it's far simpler and less error-prone.我寧願做後者,因爲它更簡單,更不容易出錯。

So the question relates to what framework would be best suited to my needs.因此,問題涉及哪種框架最適合我的需求。 The following is a list of the options I know about so far:以下是我目前所知道的選項列表:

  • Twisted : The granddaddy of Python reactor frameworks: seems complex and a bit bloated however. Twisted :Python reactor 框架的鼻祖:看起來很複雜而且有點臃腫。 Steep learning curve for a small task.小任務的陡峭學習曲線。
  • Eventlet : From the guys at lindenlab . Eventlet :來自lindenlab 的人 Greenlet based framework that's geared towards these kinds of tasks.面向此類任務的基於 Greenlet 的框架。 I had a look at the code though and it's not too pretty: non-pep8 compliant, scattered with prints (why do people do this in a framework!?), API seems a little inconsistent.不過我看了一下代碼,它不是太漂亮:不符合 pep8,散落着打印(爲什麼人們在框架中這樣做!?),API 似乎有點不一致。
  • PyEv : Immature, doesn't seem to be anyone using it right now though it is based on libevent so it's got a solid backend. PyEv :不成熟,現在似乎沒有人使用它,儘管它基於 libevent,所以它有一個可靠的後端。
  • asyncore : From the stdlib: über low-level, seems like a lot of legwork involved just to get something off the ground. asyncore :從 stdlib: über 低級,似乎涉及很多跑腿工作只是爲了得到一些東西。
  • tornado : Though this is a server oriented product designed to server dynamic websites it does feature an async HTTP client and a simple ioloop .龍捲風:雖然這是一個面向服務器的產品,旨在爲動態網站提供服務器,但它確實具有異步 HTTP 客戶端和簡單的ioloop 功能 Looks like it could get the job done but not what it was intended for.看起來它可以完成工作,但不是它的目的。 [edit: doesn't run on Windows unfortunately, which counts it out for me - its a requirement for me to support this lame platform] [編輯:不幸的是,它不能在 Windows 上運行,這對我來說很重要——這是我支持這個蹩腳平臺的必要條件]

Is there anything I have missed at all?有什麼我錯過的嗎? Surely there must be a library out there that fits the sweet-spot of a simplified async networking library!肯定有一個庫適合簡化的異步網絡庫的最佳位置!

[edit: big thanks to intgr for his pointer to this page . [編輯:非常感謝intgr指向此頁面 If you scroll to the bottom you will see there is a really nice list of projects that aim to tackle this task in one way or another.如果你滾動到底部,你會看到有一個非常好的項目列表,旨在以一種或另一種方式解決這個任務。 It seems actually that things have indeed moved on since the inception of Twisted: people now seem to favour a co-routine based solution rather than a traditional reactor / callback oriented one.實際上,自 Twisted 誕生以來,事情確實發生了變化:人們現在似乎更喜歡基於協程的解決方案,而不是傳統的面向反應器/回調的解決方案。 The benefits of this approach are clearer more direct code: I've certainly found in the past, especially when working with boost.asio in C++ that callback based code can lead to designs that can be hard-to-follow and are relatively obscure to the untrained eye.這種方法的好處是更清晰更直接的代碼:我在過去肯定發現,尤其是在 C++ 中使用boost.asio時,基於回調的代碼可能導致設計難以遵循並且相對模糊未經訓練的眼睛。 Using co-routines allows you to write code that looks a little more synchronous at least.使用協同程序可以讓您編寫至少看起來更同步的代碼。 I guess now my task is to work out which one of these many libraries I like the look of and give it a go!我想現在我的任務是找出我喜歡這些庫中的哪一個並試一試! Glad I asked now...]很高興我現在問...]

[edit: perhaps of interest to anyone who followed or stumbled on this this question or cares about this topic in any sense: I found a really great writeup of the current state of the available tools for this job] [編輯:任何關注或偶然發現此問題或在任何意義上關心此主題的人都可能感興趣:我發現了有關此工作可用工具當前狀態的非常好的文章]


解決方案:

參考一: https://stackoom.com/question/7ec6
參考二: A clean, lightweight alternative to Python's twisted? [closed]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章