简体   繁体   中英

Thread to add items in Treeview - pygtk

I am trying to develop a downloader app in pygtk So when a user adds a url following actions happen

  • addUrl()

which calls

  • validateUrl()

  • getUrldetails()

So it took a little while to add the url to the list because of urllib.urlopen delay so i tried to implement threads. I added the following code to main window

thread.start_new_thread(addUrl, (self,url, )) I passed a reference to the main window so that i can access the list from thread but nothing seems to happen

I think that you check this thread first How to use threading in Python? . for example: import Queue import threading import urllib2

# called by each thread
def get_url(q, url):
    q.put(urllib2.urlopen(url).read())

theurls = '''http://google.com http://yahoo.com'''.split()

q = Queue.Queue()

for u in theurls:
    t = threading.Thread(target=get_url, args = (q,u))
    t.daemon = True
    t.start()

s = q.get()
print s

Hope this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM