Python 的类似 Erlang 的并发性?
Python 有没有像 Erlang 那样具有并发性的东西,特别是网络上的透明参与者?我看过诸如 greenlet 和 stackless,但他们似乎对参与者没有网络透明度。
我仍然无法完全跨越 Erlang/OTP 的障碍,所以我很感兴趣是否有离家更近的东西。
Is there anything for Python that has concurrency like Erlang does, particulary transparent actors over networks? I've looked at things like greenlet and stackless, but they don't seem to have network transparency for actors.
I still can't quite jump the hurdle of Erlang/OTP so I'm interested if there's something closer to home.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
与其试图让 Python 更像 Erlang,不如让 Erlang 更像 Python 怎么样?
Efene 和 Elixir 是生成 BEAM 文件的语言编译器,可以利用 Erlang BEAM 模拟器的所有功能,包括网络透明消息传递。
Efene 有一个“ifene”变体,它定义带有空格的块,就像 Python 一样。除此之外,它与 JavaScript 最相似。
Elixir 语法最接近 Ruby。
这两种语言都比 Erlang 更接近 Python。
Instead of trying to make Python more like Erlang, how about making Erlang more like Python?
Efene and Elixir are language compilers that produce BEAM files which can take advantage of all the features of the Erlang BEAM emulator including network-transparent messaging.
Efene has an "ifene" variant that defines blocks with whitespace, like Python. Otherwise, it is most similar to JavaScript.
Elixir syntax is closest to Ruby.
Both languages are closer to Python than Erlang.
并不真地。 Erlang 是从一开始就为支持参与者而设计的,而 Python 则不是。我能想到的最符合要求的是 Candygram 库,但即使如此也不是完全正确。
Not really. Erlang was designed from the ground up to support actors, Python wasn't. The closest I can think of that fits the bill is the Candygram library, but even that's not quite right.
尝试 Axon / Kamaelia
它与 PyPy 兼容,因此您可以获得基于参与者/流的编程,并通过 PyPy 的 JIT 显着加快执行速度。
Try Axon / Kamaelia
It's compatible with PyPy, so you get actor/flow-based programming and significantly accelerated execution speeds with PyPy's JIT.
caine,我创建的一个包,并以 这家伙,实现了
caine.SupportingActor
,一个用户友好的并发python 的演员模型。默认情况下, caine.SupportingActor 类具有以下属性/功能:
inbox
:托管队列。消息像foo.inbox.put('bar')
一样传递给 actor。timeout
:超时之前消息接收之间允许的秒数。receive
:使用收件箱中的消息执行的函数,需要实现。handle
:引发异常时执行的函数。callback
:处理完成时执行的函数。cut
:调用时结束处理。此外,
caine.SupportingCast
类继承了caine.SupportingActor
的所有功能,同时允许指定数量的参与者分别处理来自同一收件箱的消息,而无需重复。caine, a package I created and named after this guy, implements
caine.SupportingActor
, a user-friendly concurrent actor model for python.By default,
caine.SupportingActor
class has the following attributes/functions:inbox
: a managed queue. Messages are passed to the actor like so,foo.inbox.put('bar')
.timeout
: the allowed number of seconds between message receptions before timing out.receive
: a function to execute using messages from the inbox, requires implementation.handle
: a function to execute when an exception is raised.callback
: a function to execute when processing is complete.cut
: ends processing when called.Additionally the
caine.SupportingCast
class inherits all the functions ofcaine.SupportingActor
while allowing a specified number of actors to each process messages from the same inbox without duplication.这并不是真正的并发,但是 Celery 可能会为您提供一些您想要的东西,在通过网络分配任务负载方面。
It's not really concurrency, but Celery may give you something of what your looking for, in terms of distributing task load over a network.
请参阅 Pykka。我不确定它如何处理错误。
See Pykka. I'm not sure how it handles errors.
另外,对于其中一些功能,请参阅 stackless python。
Also for some of these features see stackless python.