471,305 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

interesting threading result..

Hi..
I have a interesting threading result..

class GetData(threading.Thread):
def __init__(self, name):
threading.Thread.__init__(self)
self.name = name

def run(self):
self.data={2:3, 3:4...}

current = GetData(a)
nlist.append(current)
current.start()
end=[]
dd=nlist[0]
dd.join()
result=dd.data
print result
(and it gives me : {2:3, 3:4...} )
end.append(result)
print end
(and it gives me: [<GetData(Thread-3, stopped)>, {2:3, 3:4...}] )
What happen ??
What is the <GetData(Thread-3, stopped)>, ?
In the first print there isn't it but second print it is in there.
I don't want <GetData(Thread-3, stopped)>..
How can i escape from it ?

I'm sorry my bad english.
King regards..

Oct 29 '07 #1
1 969
En Mon, 29 Oct 2007 20:26:40 -0300, Abandoned <be*****@gmail.comescribió:
Now this is my real code and the problem continue.
What is the mistake?
I don't see where you define "query" so this can't be your complete code.
>
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()}
Here, you make nglist and nlist refer to the same object (a dictionary,
not a list!)
To be short: nglist and nlist are the same thing
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()
Here, you append current to nglist[i]. current is an instance of the
GetData class, a Thread. As nglist is the same thing as nlist, nlist[i]
contains a GetData instance too.
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}]}
It's not surprising to see here the object appended above.

I can't say how to improve/fix this because I can't see the purpose of all
this. Could you explain what do you want to do exactly?

--
Gabriel Genellina

Oct 30 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Joe Wong | last post: by
1 post views Thread by | last post: by
5 posts views Thread by Francois De Serres | last post: by
11 posts views Thread by Mark Rae | last post: by
3 posts views Thread by Asad | last post: by
14 posts views Thread by Akihiro KAYAMA | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.