0
我想使用由deco模塊提供的併發功能。該代碼工作沒有多線程如在這裏的答案....多進程子功能不返回任何結果
Extract specific columns from a given webpage
但是,下面的代碼不會對finallist返回任何元素。 (它是空的)。從print語句中可以看出,它在「slow」的函數範圍內返回了一些結果。但爲什麼外表是空的?
import urllib.request
from bs4 import BeautifulSoup
from deco import concurrent, synchronized
finallist=list()
urllist=list()
@concurrent
def slow(url):
#print (url)
try:
page = urllib.request.urlopen(url).read()
soup = BeautifulSoup(page)
mylist=list()
for anchor in soup.find_all('div', {'class':'col-xs-8'})[:9]:
mylist.append(anchor.text)
urllist.append(url)
finallist.append(mylist)
#print (mylist)
print (finallist)
except:
pass
@synchronized
def run():
finallist=list()
urllist=list()
for i in range(10):
url='https://pythonexpress.in/workshop/'+str(i).zfill(3)
print (url)
slow(url)
slow.wait()