threadring.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:zippy 作者: securesystemslab 项目源码 文件源码
def main(n = int(sys.argv[1]), n_threads=503, cycle=itertools.cycle):

    def worker(worker_id):

        n = 1
        while True:
            print n
            if n > 0:
                n = (yield (n - 1))
            else:
                print worker_id
                raise StopIteration


    threadRing = [worker(w) for w in xrange(1, n_threads + 1)]
    for t in threadRing: foo = t.next()           # start exec. gen. funcs
    sendFuncRing = [t.send for t in threadRing]   # speed...
    for send in cycle(sendFuncRing):
        try:
            n = send(n)
        except StopIteration:
            break
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号