def download_one(cc): image = yield from get_flag(cc) # 유일한 차이점 # 기존 코드 # image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_many(cc_list): # <8> for cc in sorted(cc_list): # <9> image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return len(cc_list)
def download_one( cc ): # Function to download a single image; this is what each thread will execute. image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): image = yield from get_flag(cc) country = yield from get_country(cc) show(cc) filename = '{} - {}.gif'.format(country,cc) save_flag(image,filename) return cc
def download_one(cc): # ➏ download_one 函数也必须是协程,因为用到了yield from。 image = yield from get_flag( cc ) # ➐ 与依序下载版 download_one 函数唯一的区别是这一行中的 yield from;函数定义体中的其他代码与之前完全一样。 show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc,name): # <3> image = get_flag(cc) show(cc) # print(name,end=' ') # 只是为了显示传参数 sys.stdout.flush() save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): """ 画像を1枚ダウンロードする関数です。スレッドはそれぞれこれを実行します。 """ image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): """ 下载一个图像的函数,在各个线程中执行的函数 """ image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): """ 下载一个图像的函数,这是在各个线程中执行的函数。 :param cc: :return: """ image = get_flag(cc) show(cc) save_flag(image, cc.lower() + ".gif") return cc
async def download_one(loop, country): '''''' # ClientSession error를 잡기 위해 session을 전달 # loop = loop를 주어 __aexit__ 처리 async with aiohttp.ClientSession(loop=loop) as session: image = await get_flag(session, country) show(country) save_flag(image, country.lower(), type='png') return country
async def main( ): # Declare as async, since we want to use it in the event loop t0 = time.time() futures = [] for cc in flag_list(): show(cc) url = f'{BASE_URL}/{cc}' futures.append(loop.run_in_executor(None, requests.get, url)) for future in futures: response = await future save_flag(response.content, response.url.split('/')[-1]) t1 = time.time() - t0 print(f'\n{t1:.2f}sec')
def download_one(cc): """ download_oneもyield fromを用いているので、コルーチンでなければなりません。 """ # 以前実装したdownload_oneと異なるのは、 # この行に加わっている「yield from」の部分だけで、他は全く同じです。 image = yield from get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
async def download_one(cc, semaphore): # semaphore 参数是 asyncio.Semaphore 类的实例 # Semaphore 类是同步装置,用于限制并发请求 try: # semaphore当成上下文管理器使用,完成后自动释放 # 如果semaphore 计数器的值小于所允许的最大值,只有当前协程会阻塞,如果大于的话,当前进程都会堵塞 async with semaphore: image = await get_flag(cc) except Exception as exc: raise FetchError(cc) from exc else: save_flag(image, cc.lower() + '.gif') status = HTTPStatus.ok msg = 'ok' show(cc) return Result(status, cc)
def download_one(country): img = get_img(FLAGS_GETTER_LINK, country) show(country) download_flag(img, country)
def download_one(cc): image = get_pic(cc) show(cc) save_pic(image, cc + ".gif") return cc
def download_one(cc): # The only difference from the sequential implementation of download_one are the words "yield from" in this line; the rest of the function is exactly as before image = yield from get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): # <3> image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): image = yield from get_flag(cc) show(cc) save_flag(image, 'gif2/' + cc.lower() + '.git') return cc
def download_one(suffix): image = yield from get_flag(suffix) show(suffix) save_flag(image, suffix) return suffix
async def download_one(client, cc): # <6> image = await get_flag(client, cc) # <7> show(cc) save_flag(image, cc.lower() + '.gif') return cc
async def download_one(cc): img = await get_flag(cc) show(cc) save_flag(img, cc + '.gif') return cc
async def download_one(cc): # <6> image = await get_flag(cc) # <7> show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): # <6> image = yield from get_flag(cc) # <7> show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): image = get_flag(cc) show(cc) save_flag(image, cc.lower() + ".gif") return cc
async def download_one(cc): async with aiohttp.ClientSession() as session: image = await get_flag(session, cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
async def download_one(cc): show(cc) url = f'{BASE_URL}/{cc}' future = loop.run_in_executor(None, requests.get, url) response = await future save_flag(response.content, cc)
def download_one(name): image = yield from get_img(name) show(name) download_flag(image, name) return name
async def download_one(loop, country): async with aiohttp.ClientSession(loop=loop) as session: image = await get_flag(session, country) show(country) save_flag(image, country.lower(), type='png') return country
def download_one(cc): image = yield from get_flag(cc) show(cc) save_flag(image, cc.lower() + ".gif") return cc
def download_one(cc): image = yield from get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def dl_one(cc): image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
async def download_one(session, cc): image = await get_flag(session, cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): # <3> 하나의 이미지를 내려받을 함수; 각 스레드에서 이 함수 실행 예정 image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
async def download_one(cc): """一级被调协程,代表一项下载任务""" image = await get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): """将串行版本中下载单张图像的代码剥离出来""" image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): image = get_flag(cc) show(cc) save_flag(image, cc.lower() + '.gif') return cc
def download_one(cc): img = get_flag(cc) show(cc) save_flag(img, cc.lower() + ".gif") return cc