interesting threading result..
Abandoned
besturk at gmail.com
Mon Oct 29 19:26:40 EDT 2007
On Oct 29, 11:29 pm, Alan Franzoni
<alan.franzoni_inva... at geemail.invalid> wrote:
> Il Mon, 29 Oct 2007 09:08:01 -0700, Abandoned ha scritto:
>
> > I'm sorry my bad english.
> > King regards..
>
> You must have messed up with something. You didn't post a working snippet
> in first place, so you should do it now. I suppose you're working with some
> editor or IDE which mantains the very same instance of a python interpreter
> in memory; you probably have done something like
>
> end.append(current)
>
> at a certain point in your tests.
>
> I converted your pseudocode to python like that:
>
> import threading
>
> class GetData(threading.Thread):
> def __init__(self, name):
> threading.Thread.__init__(self)
> self.name = name
>
> def run(self):
> self.data={2:3, 3:4}
>
> nlist = []
> current = GetData("a")
> nlist.append(current)
> current.start()
> end=[]
> dd=nlist[0]
> dd.join()
> result=dd.data
> print result
> end.append(result)
> print end
>
> and I just get the result I would expect:
>
> {2: 3, 3: 4}
> [{2: 3, 3: 4}]
>
> --
> Alan Franzoni <alan.franzoni.... at gmail.com>
> -
> Togli .xyz dalla mia email per contattarmi.
> Remove .xyz from my address in order to contact me.
> -
> GPG Key Fingerprint (Key ID = FE068F3E):
> 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
Thanks you..
Now this is my real code and the problem continue.
What is the mistake?
import threading
class GetData(threading.Thread):
def __init__(self, name):
threading.Thread.__init__(self)
self.name = name
def run(self):
self.data={2:3, 3:4}
i=0
datas={"n": [['msn']]}
nglist=nlist={0: list()}
for x in query:
tip=x
for a in datas[x]:
for o in a:
if len(o)>1:
current = GetData(o)
nglist[i].append(current)
current.start()
i=i+1
for x in range(0,len(nglist)):
for jk in range(0,len(nglist[x])):
jkl=nglist[x][jk]
jkl.join()
sonuc=jkl.data
nlist[x].append(sonuc)
print nlist
{0: [<GetData(Thread-1, stopped)>, {2: 3, 3: 4}]}
More information about the Python-list
mailing list