2013-03-25 54 views
0

我想這樣當用戶添加一個網址下列行爲發生主題添加項目在樹視圖 - pygtk的

  • addUrl()
發展在PyGTK中 一個下載的應用程序

哪叫

  • validateUrl()

  • getUrldetails()

於是花了一小會兒的網址添加到列表中,因爲urllib.urlopen延遲 ,所以我試圖執行線程。我下面的代碼添加到主窗口

thread.start_new_thread(addUrl, (self,url,)) 我傳遞給主窗口的引用,這樣我可以從線程 訪問列表,但似乎沒有發生

+0

你的問題到底是什麼?什麼名單? – acattle 2013-03-28 03:00:54

+0

我認爲你先檢查這個線程http://stackoverflow.com/questions/2846653/python-multithreading-for-dummies。 希望這可以幫助你。 – MyMy 2013-03-28 14:12:41

回答

0

我認爲你檢查此線程首先How to use threading in Python?例如: 進口隊列 進口線程 進口的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 

希望這有助於你。