You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
449 B
Python
15 lines
449 B
Python
# loop.run_in_executor, запуск в отдельном потоке
|
|
import asyncio
|
|
from urllib.request import urlopen
|
|
|
|
# a synchronous function
|
|
def sync_get_url(url):
|
|
return urlopen(url).read()
|
|
|
|
async def load_url(url, loop=None):
|
|
future = loop.run_in_executor(None, sync_get_url, url)
|
|
response = await future
|
|
print(len(response))
|
|
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(load_url("http://sinfo/", loop=loop)) |