$builder->add('category_id', EntityType::class, [
'class' => Category::class,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('o')->orderBy('o.title', 'ASC');
},
'placeholder' => 'Выбрать категорию',
'choice_label' => 'title',
]);
async with session.get(url, timeout=40, headers=headers) as response:
timeout = aiohttp.ClientTimeout(connect=2)
async with session.get(url,timeout=timeout,headers=headers) as response:
from domainlist import site_pages, real_site,site_pages_mini, site_pages_react, site_pages_all,site_pages_random_3000,site_pages_random_1000, site_pages_random_2000, list_5000
from memory_profiler import memory_usage
import random
import aiohttp
import asyncio
import time
async def fetch(url, session):
headers = {
"Accept":"application/json, text/plain, */*",
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
"Accept-Language":"zh-CN,zh;q=0.9",
"accept-encoding":"gzip, deflate"}
try:
async with session.get(url, timeout=0.1, headers=headers) as response:
date = response.headers.get("DATE")
code_status = response.history[0].status if response.history else response.status
print('%s -> Status Code: %s' % (url, code_status))
return await response.read()
except Exception as e:
print("{} : exeption {}/ class {}".format(url, e, e.__class__))
pass
async def bound_fetch(sem, url, session):
async with sem:
await fetch(url, session)
async def run():
tasks = []
check_site = real_site
sem = asyncio.Semaphore(1000)
async with aiohttp.ClientSession() as session:
for url in check_site:
task = asyncio.ensure_future(bound_fetch(sem, url, session))
tasks.append(task)
responses = asyncio.gather(*tasks)
await responses
loop = asyncio.get_event_loop()
global_start_time = time.time()
future = asyncio.ensure_future(run())
loop.run_until_complete(future)
print("--- %s seconds ---" % (time.time() - global_start_time))
sem = asyncio.Semaphore(1000)
async with aiohttp.ClientSession() as session:
for url in check_site:
task = asyncio.ensure_future(bound_fetch(sem, url, session))
tasks.append(task)
responses = asyncio.gather(*tasks)
await responses
loop = asyncio.get_event_loop()
global_start_time = time.time()
future = asyncio.ensure_future(run())
loop.run_until_complete(future)
http://yandex.ru : exeption / class <class 'concurrent.futures._base.TimeoutError'>
http://yandex.ru -> Status Code: 302
Wed, 04 Sep 2019 10:23:46 GMT:https://yandex.ru/ with delay