python - Python 中具有 native 线程的 CSP channel

标签 python python-3.x channel alt

我正在寻找 Python 中 native 线程之上的 CSP channel 的实现。我见过一些图书馆,但它们包括除厨房水槽之外的所有内容。

具体来说,我正在寻找在多个 channel 上等待一组发送和接收操作中的第一个操作的能力,并且将第一个完成的操作的结果返回给我,或者调用回调。

以下是一些相关上下文链接:

最佳答案

是的,我的库 python-csp 拥有所有这些。您可以在这里获取该库:https://github.com/futurecore/python-csp

这是一个带有 channel 和 ALTing 的简单示例(也称为非确定性选择):

>>> @process
... def send_msg(chan, msg):
...     chan.write(msg)
... 
>>> @process
... def alt_example(chan1, chan2):
...     alt = Alt(chan1, chan2)
...     print alt.select()
...     print alt.select()
... 
>>> c1, c2 = Channel(), Channel()
>>> Par(send_msg(c1, 'yes'), send_msg(c2, 'no'), alt_example(c1, c2)).start()
yes
no
>>>

我正在重构内部结构并清理内容,因此请密切关注很快的发布,或者如果您愿意,请随时给我发离线电子邮件。

关于python - Python 中具有 native 线程的 CSP channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8551162/

相关文章:

python - 删除 django 模板中的 [u'']

python - 欧拉计划 #23 错误答案

python - pandas.read_sql_query() 抛出 TypeError : 'NoneType' object is not iterable

go - 为什么我的 Golang channel 写入永远阻塞?

python - 为什么 SIGVTALRM 不在 time.sleep() 内部触发?

python - 有没有办法在 Python 中打印特殊字符?

python - 三次Hermite样条插值python

python - 使用Python从数据库中提取

go - 拉 0 大小的 golang chan

java - 如何在 Java 中找到 ReadableByteChannel 的大小?