0
gevent (1.0b4)를 사용하여 html 파일을 다운로드 할 때 진행률 표시 줄을 사용하여 진행률을 표시하려고합니다.
아래 코드를 작성했지만 코드에 항상 오류가 있습니다. 누군가가 도울 수 있기를 바랍니다.진행 표시 줄 및 gevent
file_path='temp'
url_count=len(urls)
def progress_bar(file_path, file_count): #
file_count = long(file_count)
width = 32
last_count = 0
try:
while True:
if os.path.isdir(file_path):
current_count = len(glob.glob1(myPath,"*.html"))
percentage = current_count*100/file_count
current_width = width*percentage/100
sys.stderr.write('% 3d%% [%s%s] %s/s \r' % (percentage, '#'*current_width, ' '*(width-current_width), current_count - last_count))
last_count = current_count
time.sleep(1)
except:
sys.stderr.write('100%% [%s]\n' % ('#'*width))
def print_head(url):
data = urllib2.urlopen(url)
htmlFile = open(file_path+'/'+url+'.html', 'w')
htmlFile.write(data.read())
htmlFile.close()
raise Exception("done!")
jobs = [gevent.spawn(print_head, url) for url in urls]
x = [g.link_exception(progress_bar,file_path,url_count) for g in jobs]
gevent.joinall(jobs)
역 추적
Traceback (most recent call last):
File "E:\tt\test.py", line 39, in <module>
x = [g.link_exception(progress_bar,file_path,url_count) for g in jobs] #
TypeError: link_exception() takes at most 3 arguments (4 given)
:
업데이트 : 난 당신이 뭔가를 사용할 수있는 바로 그때 당신을 이해한다면 ? link_exception()도 인자를 두 개 취합니다 (위에서 'file_path'인수를 제거함). 다른 오류 메시지가 표시됩니다. TypeError : 'str'객체를 호출 할 수 없습니다. –
@Matt Elson, 업데이트보기 –