文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>stackless多核测试

stackless多核测试

时间:2009-06-19  来源:nahuat

#!/usr/bin/pypy-stackless
# -*- coding: utf8 -*-

import stackless, time

c1, c2 = stackless.channel(), stackless.channel()

def log(msg):
    t = time.time()
    print '[%s.%06d]' % (time.strftime('%T', time.localtime(t)), (t - int(t)) * 1000000), msg

def consumer(name, channel):
    log('entry ' + name)
    log(channel.receive())
    time.sleep(3)
    log('leave ' + name)

def productor():
    log('entry productor')
    c1.send(('hello', 'world'))
    c2.send(('foo bar',))
    log('leave productor')

stackless.tasklet(productor)()
stackless.tasklet(consumer)('one', c1)
stackless.tasklet(consumer)('two', c2)
stackless.run()

"""
以下是执行结果
[18:28:38.464008] entry productor
[18:28:38.464564] entry one
[18:28:38.464715] ('hello', 'world')
[18:28:41.466892] leave one
[18:28:41.467211] entry two
[18:28:41.467592] ('foo bar',)
[18:28:44.470731] leave two
[18:28:44.471030] leave productor
"""
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载