Python论坛  - 讨论区

标题:[python-chinese] 对字典的多现程操作

2006年08月10日 星期四 14:01

bird devdoer devdoer at gmail.com
Thu Aug 10 14:01:14 HKT 2006

假设多个线程共享字典m

多个线程同时执行
for key in m.keys():

    ....

会出错么 ,需要同步么
也就是多个线程分别有自己的iterator变量,还是共享一个iterator

-- 
devdoer
devdoer at gmail.com
http://project.mytianwang.cn/cgi-bin/blog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/69ed869f/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:05

Robert Chen search.pythoner at gmail.com
Thu Aug 10 14:05:02 HKT 2006

需要同步的

On 8/10/06, bird devdoer <devdoer at gmail.com> wrote:
>
> 假设多个线程共享字典m
>
> 多个线程同时执行
> for key in m.keys():
>
>     ....
>
> 会出错么 ,需要同步么
> 也就是多个线程分别有自己的iterator变量,还是共享一个iterator
>
> --
> devdoer
> devdoer at gmail.com
> http://project.mytianwang.cn/cgi-bin/blog
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
Robert
Python源码剖析――http://blog.donews.com/lemur/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/98563f07/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:08

bird devdoer devdoer at gmail.com
Thu Aug 10 14:08:59 HKT 2006

我进行的是同时读操作 如果需要同步 那么python的实现应该是违背了常理了

在06-8-10,Robert Chen <search.pythoner at gmail.com> 写道:
>
> 需要同步的
>
>  On 8/10/06, bird devdoer <devdoer at gmail.com> wrote:
>
> >  假设多个线程共享字典m
>
> 多个线程同时执行
> for key in m.keys():
>
>     ....
>
> 会出错么 ,需要同步么
> 也就是多个线程分别有自己的iterator变量,还是共享一个iterator
>
> --
> devdoer
> devdoer at gmail.com
> http://project.mytianwang.cn/cgi-bin/blog
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to   python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
>
> --
> Robert
> Python源码剖析――http://blog.donews.com/lemur/
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
devdoer
devdoer at gmail.com
http://project.mytianwang.cn/cgi-bin/blog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/e68f3b3f/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:16

bird devdoer devdoer at gmail.com
Thu Aug 10 14:16:33 HKT 2006

刚才验证了不需要同步

import threading,time
m={1:0,2:0,3:0,4:0}
def f(d):
 for i in d.iterkeys():
  print i
  time.sleep(3)

for x in xrange(3):
 t=threading.Thread(target=f,args=(m,))
 t.start(


在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
>
> 我进行的是同时读操作 如果需要同步 那么python的实现应该是违背了常理了
>
> 在06-8-10,Robert Chen <search.pythoner at gmail.com> 写道:
>
> > 需要同步的
> >
> >  On 8/10/06, bird devdoer < devdoer at gmail.com> wrote:
> >
> > >  假设多个线程共享字典m
> >
> > 多个线程同时执行
> > for key in m.keys():
> >
> >     ....
> >
> > 会出错么 ,需要同步么
> > 也就是多个线程分别有自己的iterator变量,还是共享一个iterator
> >
> > --
> > devdoer
> > devdoer at gmail.com
> > http://project.mytianwang.cn/cgi-bin/blog
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >
> >
> > --
> > Robert
> > Python源码剖析――http://blog.donews.com/lemur/
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
>
>
> --
> devdoer
> devdoer at gmail.com
> http://project.mytianwang.cn/cgi-bin/blog
>



-- 
devdoer
devdoer at gmail.com
http://project.mytianwang.cn/cgi-bin/blog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/bb0d7546/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:18

刘鑫 march.liu at gmail.com
Thu Aug 10 14:18:58 HKT 2006

你自己没有给出详细说明咯……一般来讲并发操作都是同步写操作的。

在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
>
> 刚才验证了不需要同步
>
> import threading,time
> m={1:0,2:0,3:0,4:0}
> def f(d):
>  for i in d.iterkeys():
>   print i
>   time.sleep(3)
>
> for x in xrange(3):
>  t=threading.Thread(target=f,args=(m,))
>  t.start(
>
>
> 在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
>
> > 我进行的是同时读操作 如果需要同步 那么python的实现应该是违背了常理了
> >
> > 在06-8-10,Robert Chen <search.pythoner at gmail.com > 写道:
> >
> > > 需要同步的
> > >
> > >  On 8/10/06, bird devdoer < devdoer at gmail.com > wrote:
> > >
> > > >  假设多个线程共享字典m
> > >
> > > 多个线程同时执行
> > > for key in m.keys():
> > >
> > >     ....
> > >
> > > 会出错么 ,需要同步么
> > > 也就是多个线程分别有自己的iterator变量,还是共享一个iterator
> > >
> > > --
> > > devdoer
> > > devdoer at gmail.com
> > > http://project.mytianwang.cn/cgi-bin/blog
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese at lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request at lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> > >
> > >
> > > --
> > > Robert
> > > Python源码剖析――http://blog.donews.com/lemur/
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese at lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request at lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> >
> >
> > --
> > devdoer
> > devdoer at gmail.com
> > http://project.mytianwang.cn/cgi-bin/blog
> >
>
>
>
> --
> devdoer
> devdoer at gmail.com
> http://project.mytianwang.cn/cgi-bin/blog
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
欢迎访问:
http://blog.csdn.net/ccat

刘鑫
March.Liu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/fc23e9ec/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:21

Robert Chen search.pythoner at gmail.com
Thu Aug 10 14:21:57 HKT 2006

呵呵,是的,偶理解错意思了...... :)

On 8/10/06, bird devdoer <devdoer at gmail.com> wrote:
>
> 刚才验证了不需要同步
>
> import threading,time
> m={1:0,2:0,3:0,4:0}
> def f(d):
>  for i in d.iterkeys():
>   print i
>   time.sleep(3)
>
> for x in xrange(3):
>  t=threading.Thread(target=f,args=(m,))
>  t.start(
>
>
> 在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
>
> > 我进行的是同时读操作 如果需要同步 那么python的实现应该是违背了常理了
> >
> > 在06-8-10,Robert Chen <search.pythoner at gmail.com > 写道:
> >
> > > 需要同步的
> > >
> > >  On 8/10/06, bird devdoer < devdoer at gmail.com > wrote:
> > >
> > > >  假设多个线程共享字典m
> > >
> > > 多个线程同时执行
> > > for key in m.keys():
> > >
> > >     ....
> > >
> > > 会出错么 ,需要同步么
> > > 也就是多个线程分别有自己的iterator变量,还是共享一个iterator
> > >
> > > --
> > > devdoer
> > > devdoer at gmail.com
> > > http://project.mytianwang.cn/cgi-bin/blog
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese at lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request at lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> > >
> > >
> > > --
> > > Robert
> > > Python源码剖析――http://blog.donews.com/lemur/
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese at lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request at lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> >
> >
> > --
> > devdoer
> > devdoer at gmail.com
> > http://project.mytianwang.cn/cgi-bin/blog
> >
>
>
>
> --
> devdoer
> devdoer at gmail.com
> http://project.mytianwang.cn/cgi-bin/blog
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
Robert
Python源码剖析――http://blog.donews.com/lemur/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/b68e5c52/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:25

bird devdoer devdoer at gmail.com
Thu Aug 10 14:25:01 HKT 2006

恩 我没有说清楚  是同时实现 for key in m.keys()...

在06-8-10,Robert Chen <search.pythoner at gmail.com> 写道:
>
> 呵呵,是的,偶理解错意思了...... :)
>
>
> On 8/10/06, bird devdoer <devdoer at gmail.com> wrote:
> >
> >  刚才验证了不需要同步
> >
> > import threading,time
> > m={1:0,2:0,3:0,4:0}
> > def f(d):
> >  for i in d.iterkeys():
> >   print i
> >   time.sleep(3)
> >
> > for x in xrange(3):
> >  t=threading.Thread(target=f,args=(m,))
> >  t.start(
> >
> >
> > 在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
> >
> > > 我进行的是同时读操作 如果需要同步 那么python的实现应该是违背了常理了
> > >
> > > 在06-8-10,Robert Chen <search.pythoner at gmail.com > 写道:
> > >
> > > > 需要同步的
> > > >
> > > >  On 8/10/06, bird devdoer < devdoer at gmail.com > wrote:
> > > >
> > > > >  假设多个线程共享字典m
> > > >
> > > > 多个线程同时执行
> > > > for key in m.keys():
> > > >
> > > >     ....
> > > >
> > > > 会出错么 ,需要同步么
> > > > 也就是多个线程分别有自己的iterator变量,还是共享一个iterator
> > > >
> > > > --
> > > > devdoer
> > > > devdoer at gmail.com
> > > > http://project.mytianwang.cn/cgi-bin/blog
> > > >
> > > > _______________________________________________
> > > > python-chinese
> > > > Post: send python-chinese at lists.python.cn
> > > > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > > > Unsubscribe: send unsubscribe to
> > > > python-chinese-request at lists.python.cn
> > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Robert
> > > > Python源码剖析――http://blog.donews.com/lemur/
> > > >
> > > > _______________________________________________
> > > > python-chinese
> > > > Post: send python-chinese at lists.python.cn
> > > > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > > > Unsubscribe: send unsubscribe to
> > > > python-chinese-request at lists.python.cn
> > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > > >
> > > >
> > >
> > >
> > > --
> > > devdoer
> > > devdoer at gmail.com
> > > http://project.mytianwang.cn/cgi-bin/blog
> > >
> >
> >
> >
> > --
> > devdoer
> > devdoer at gmail.com
> > http://project.mytianwang.cn/cgi-bin/blog
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
>
>
> --
> Robert
> Python源码剖析――http://blog.donews.com/lemur/
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
devdoer
devdoer at gmail.com
http://project.mytianwang.cn/cgi-bin/blog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/adfb83ec/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:27

bird devdoer devdoer at gmail.com
Thu Aug 10 14:27:26 HKT 2006

没有写 主要是iterator的操作 ,如果是共享同一个iterator的话,可能会出现线程1读第一个,线程2读第二个的情况,现在看来不是的。

在06-8-10,刘鑫 <march.liu at gmail.com> 写道:
>
> 你自己没有给出详细说明咯……一般来讲并发操作都是同步写操作的。
>
>
> 在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
> >
> >  刚才验证了不需要同步
> >
> > import threading,time
> > m={1:0,2:0,3:0,4:0}
> > def f(d):
> >  for i in d.iterkeys():
> >   print i
> >   time.sleep(3)
> >
> > for x in xrange(3):
> >  t=threading.Thread(target=f,args=(m,))
> >  t.start(
> >
> >
> > 在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
> >
> > > 我进行的是同时读操作 如果需要同步 那么python的实现应该是违背了常理了
> > >
> > > 在06-8-10,Robert Chen <search.pythoner at gmail.com > 写道:
> > >
> > > > 需要同步的
> > > >
> > > >  On 8/10/06, bird devdoer < devdoer at gmail.com > wrote:
> > > >
> > > > >  假设多个线程共享字典m
> > > >
> > > > 多个线程同时执行
> > > > for key in m.keys():
> > > >
> > > >     ....
> > > >
> > > > 会出错么 ,需要同步么
> > > > 也就是多个线程分别有自己的iterator变量,还是共享一个iterator
> > > >
> > > > --
> > > > devdoer
> > > > devdoer at gmail.com
> > > > http://project.mytianwang.cn/cgi-bin/blog
> > > >
> > > > _______________________________________________
> > > > python-chinese
> > > > Post: send python-chinese at lists.python.cn
> > > > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > > > Unsubscribe: send unsubscribe to
> > > > python-chinese-request at lists.python.cn
> > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Robert
> > > > Python源码剖析――http://blog.donews.com/lemur/
> > > >
> > > > _______________________________________________
> > > > python-chinese
> > > > Post: send python-chinese at lists.python.cn
> > > > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > > > Unsubscribe: send unsubscribe to
> > > > python-chinese-request at lists.python.cn
> > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > > >
> > > >
> > >
> > >
> > > --
> > > devdoer
> > > devdoer at gmail.com
> > > http://project.mytianwang.cn/cgi-bin/blog
> > >
> >
> >
> >
> > --
> > devdoer
> > devdoer at gmail.com
> > http://project.mytianwang.cn/cgi-bin/blog
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
>
>
> --
> 欢迎访问:
> http://blog.csdn.net/ccat
>
>
> 刘鑫
> March.Liu
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
devdoer
devdoer at gmail.com
http://project.mytianwang.cn/cgi-bin/blog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/ef84461c/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:27

limodou limodou at gmail.com
Thu Aug 10 14:27:39 HKT 2006

On 8/10/06, bird devdoer <devdoer at gmail.com> wrote:
>
> 刚才验证了不需要同步
>
>
>
> import threading,time
> m={1:0,2:0,3:0,4:0}
> def f(d):
>  for i in d.iterkeys():
>   print i
>   time.sleep(3)
>
> for x in xrange(3):
>  t=threading.Thread(target=f,args=(m,))
>  t.start(
>
都是读操作当然不需要同步的,因为你没有修改数据。如果有读写操作就需要同步。如果都是写,但内容不同也可以不需要同步。

-- 
I like python!
My Blog: http://www.donews.net/limodou
My Django Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:32

bird devdoer devdoer at gmail.com
Thu Aug 10 14:32:55 HKT 2006

这个未必阿 ,如果是共享同一个iterator就需要同步的  。都是读如果不进行处理 也可能需要同步的---这句话不是专门针对python

在06-8-10,limodou <limodou at gmail.com> 写道:
>
> On 8/10/06, bird devdoer <devdoer at gmail.com> wrote:
> >
> > 刚才验证了不需要同步
> >
> >
> >
> > import threading,time
> > m={1:0,2:0,3:0,4:0}
> > def f(d):
> >  for i in d.iterkeys():
> >   print i
> >   time.sleep(3)
> >
> > for x in xrange(3):
> >  t=threading.Thread(target=f,args=(m,))
> >  t.start(
> >
> 都是读操作当然不需要同步的,因为你没有修改数据。如果有读写操作就需要同步。如果都是写,但内容不同也可以不需要同步。
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> My Django Site: http://www.djangocn.org
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
devdoer
devdoer at gmail.com
http://project.mytianwang.cn/cgi-bin/blog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/e98b57a9/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:37

刘鑫 march.liu at gmail.com
Thu Aug 10 14:37:03 HKT 2006

从代码上看,for循环每次取出的,已经是不同的iterator了:)。

在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
>
> 这个未必阿 ,如果是共享同一个iterator就需要同步的  。都是读如果不进行处理 也可能需要同步的---这句话不是专门针对python
>
> 在06-8-10,limodou <limodou at gmail.com> 写道:
> >
> > On 8/10/06, bird devdoer <devdoer at gmail.com> wrote:
> >
> > 刚才验证了不需要同步
> >
> >
> >
> > import threading,time
> > m={1:0,2:0,3:0,4:0}
> > def f(d):
> >  for i in d.iterkeys():
> >   print i
> >   time.sleep(3)
> >
> > for x in xrange(3):
> >  t=threading.Thread(target=f,args=(m,))
> >  t.start(
> >
> 都是读操作当然不需要同步的,因为你没有修改数据。如果有读写操作就需要同步。如果都是写,但内容不同也可以不需要同步。
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> My Django Site: http://www.djangocn.org
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
> _______________________________________________
>
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
>
> --
> devdoer
> devdoer at gmail.com
> http://project.mytianwang.cn/cgi-bin/blog
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
欢迎访问:
http://blog.csdn.net/ccat

刘鑫
March.Liu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/474bd8b1/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:37

limodou limodou at gmail.com
Thu Aug 10 14:37:45 HKT 2006

On 8/10/06, bird devdoer <devdoer at gmail.com> wrote:
> 这个未必阿 ,如果是共享同一个iterator就需要同步的  。都是读如果不进行处理 也可能需要同步的---这句话不是专门针对python
>
如果你的操作不是独立的是有可能需要同步。那就去同步好了。

-- 
I like python!
My Blog: http://www.donews.net/limodou
My Django Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月10日 星期四 14:42

Robert Chen search.pythoner at gmail.com
Thu Aug 10 14:42:21 HKT 2006

嗯,对,dict中的iterkeys(
)每次调用都会创建一个新的dictiterobject对象,也就是keys的iterator。所以不同线程里得到的是不同的iterator。

On 8/10/06, 刘鑫 <march.liu at gmail.com> wrote:
>
> 从代码上看,for循环每次取出的,已经是不同的iterator了:)。
>
> 在06-8-10,bird devdoer <devdoer at gmail.com> 写道:
> >
> > 这个未必阿 ,如果是共享同一个iterator就需要同步的  。都是读如果不进行处理 也可能需要同步的---这句话不是专门针对python
>
> 在06-8-10,limodou <limodou at gmail.com> 写道:
> >
> > On 8/10/06, bird devdoer < devdoer at gmail.com> wrote:
> >
> > 刚才验证了不需要同步
> >
> >
> >
> > import threading,time
> > m={1:0,2:0,3:0,4:0}
> > def f(d):
> >  for i in d.iterkeys():
> >   print i
> >   time.sleep(3)
> >
> > for x in xrange(3):
> >  t=threading.Thread(target=f,args=(m,))
> >  t.start(
> >
> 都是读操作当然不需要同步的,因为你没有修改数据。如果有读写操作就需要同步。如果都是写,但内容不同也可以不需要同步。
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> My Django Site: http://www.djangocn.org
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
> _______________________________________________
>
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
>
> --
> devdoer
> devdoer at gmail.com
> http://project.mytianwang.cn/cgi-bin/blog
>
> _______________________________________________
>
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to   python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
>
> --
>
> 欢迎访问:
> http://blog.csdn.net/ccat
>
> 刘鑫
> March.Liu
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
Robert
Python源码剖析――http://blog.donews.com/lemur/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060810/0152dc3f/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号