Python 并发编程库 goless

码农软件 · 软件分类 · 并发/并行处理框架 · 2019-09-02 19:43:11

软件介绍

使用 goless 库,你可以用 Python 语言编写 Go 语言风格的并发程序。goless 提供了 channels、select 和 gooutines 的函数,允许你使用 Go 语言漂亮和优雅的并发编程模型,但是以你习惯的 Python 方式。goless 基于 geventPyPy 或者 Stackless Python 构建,可用于 PyPy、CPython 和 Stackless Python 解释器,支持 Python 2.6 到 3.4

示例代码:

"""
A really simple example to use when demonstrating goless.
"""
from __future__ import print_function

import goless


def simple():
    channel = goless.chan()

    def goroutine():
        while True:
            value = channel.recv()
            channel.send(value ** 2)
    goless.go(goroutine)

    for i in range(2, 5):
        channel.send(i)
        squared = channel.recv()
        print('%s squared is %s' % (i, squared))

    # Output:
    # 2 squared is 4
    # 3 squared is 9
    # 4 squared is 16

if __name__ == '__main__':
    simple()

本文地址:https://codercto.com/soft/d/13739.html

Developer's Guide to Social Programming

Developer's Guide to Social Programming

Mark D. Hawker / Addison-Wesley Professional / 2010-8-25 / USD 39.99

In The Developer's Guide to Social Programming, Mark Hawker shows developers how to build applications that integrate with the major social networking sites. Unlike competitive books that focus on a s......一起来看看 《Developer's Guide to Social Programming》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具