2005年02月20日 星期日 21:44
jian wang 写道: >limodou,您好! > > 我说的是这个yield产生的对象是否是线程安全的,代码如下(dvie into python中的代码): > > > >>>>def make_counter(x): >>>> >>>> >... print 'entering make_counter' >... while 1: >... yield x >... print 'incrementing x' >... x = x + 1 >... > > >>>>counter = make_counter(2) >>>>counter >>>> >>>> >> > >>>>counter.next() >>>> >>>> >entering make_counter >2 > > >>>>counter.next() >>>> >>>> >incrementing x >3 > > >>>>counter.next() >>>> >>>> >incrementing x >4 > 若在多线程中调用counter.next()会怎么样 > > 我没有测试过,从现在了解的情况下,不同线程的迭代过程会混杂在一起。 >======= 2005-02-19 10:27:51 您在来信中写道:======= > > > >>与线程安全是一回事吗? >> >>Chun Lin Zhang wrote: >> >> >>>支持concurrent processing >>> >>> >>> >>-- >>I love python! >>My Blog: http://www.donews.net/limodou >>_______________________________________________ >>python-chinese list >>python-chinese at lists.python.cn >>http://python.cn/mailman/listinfo/python-chinese >> >> >> > >= = = = = = = = = = = = = = = = = = = = > > > 致 >礼! > > > jian wang > wangjian5748 at 163.com > 2005-02-20 > > > >------------------------------------------------------------------------ > >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050220/e184062d/attachment.html
2005年02月20日 星期日 21:53
Qiangning Hong,您好! 我的问题是在多线程的环境下调用generator对象,会怎么样? ======= 2005-02-19 17:27:43 您在来信中写道:======= >yield关键字是用来方便创建generator的。 >一个函数如果包含yield关键字,则其返回值为一个generator,跟多线程没有直接关系。 >不过developworks上有关于轻便线程(weightless thread)的文章,是使用generator来实现快速线程调度的。 > > >On Fri, 18 Feb 2005 22:56:08 +0800, jian wang <wangjian5748 at 163.com> wrote: >> 有谁用过yield这个关键字,支持多线程吗? >> >> 致 >> 礼! >> >> >> jian wang >> wangjian5748 at 163.com >> 2005-02-18 >> >> _______________________________________________ >> python-chinese list >> python-chinese at lists.python.cn >> http://python.cn/mailman/listinfo/python-chinese >> >> >> > > >-- >Excellent FOSS (Free/Open Source Software): > >Get Firefox! >http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1 > >Reclaim Your Inbox! >http://www.spreadfirefox.com/?q=affiliates&id=67907&t=183 >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese = = = = = = = = = = = = = = = = = = = = 致 礼! jian wang wangjian5748 at 163.com 2005-02-20
2005年02月20日 星期日 23:06
没试过。我想可能不是线程安全的。 你可以在访问这个yield产生的对象(叫generator)时使用锁机制来保证线程安全,如: a 为一个generator lock.acquire() b = a.next() lock.release On Sun, 20 Feb 2005 21:44:19 +0800, 刘鑫 <march.liu at gmail.com> wrote: > jian wang 写道: > limodou,您好! 我说的是这个yield产生的对象是否是线程安全的,代码如下(dvie into python中的代码): > > > def make_counter(x): ... print 'entering make_counter' ... while 1: ... > yield x ... print 'incrementing x' ... x = x + 1 ... > > > counter = make_counter(2) counter> > > counter.next() entering make_counter 2 > > > counter.next() incrementing x 3 > > > counter.next() incrementing x 4 若在多线程中调用counter.next()会怎么样 > 我没有测试过,从现在了解的情况下,不同线程的迭代过程会混杂在一起。 > -- I like python! My Blog: http://www.donews.net/limodou New Maillist: http://groups-beta.google.com/group/python-cn
Zeuux © 2025
京ICP备05028076号