1
我工作的一個Python代碼來湊一個博客,看起來有點像這樣:線程停止在Beautifulsoup命令 - 不能中斷
def main():
thread=threading.Thread(target=blogthread,args=(path,username))
thread.start()
threads.append(thread)
...
def blogthread(path,username,steem):
s=site_scraper.userposts(username)
...
def userposts(username):
f = urllib.request.urlopen(url,timeout=200)
soup = BeautifulSoup(f,'html.parser')
...
如果我打電話userposts(用戶名)直接,它工作得精細。當涉及到線程時,我的main()完成,但其他每個線程完全停留在「Beautifulsoup」行。即使主線程完成,它也不會繼續。我注意到如果我在主線程的末尾添加一個錯誤(就像一個未定義的變量),我收到一條錯誤消息,但是我的線程突然開始重新拾起並且輸出所需的結果。
我真的很困惑,謝謝你的幫助。