Skip to content

Commit

Permalink
Updated aiohttp examples to do "async with aiohttp.ClientSession()"
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Mar 23, 2022
1 parent 46a450a commit 390b7fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions docs/tutorials/webnotifier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ adapt code from the `aiohttp HTTP client tutorial`_::

class ApplicationComponent(CLIApplicationComponent):
async def run(self, ctx):
with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession() as session:
while True:
async with session.get('http://imgur.com') as resp:
await resp.text()
Expand All @@ -68,7 +68,7 @@ So, modify the code as follows::
class ApplicationComponent(CLIApplicationComponent):
async def run(self, ctx):
last_modified = None
with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession() as session:
while True:
headers = {'if-modified-since': last_modified} if last_modified else {}
async with session.get('http://imgur.com', headers=headers) as resp:
Expand Down Expand Up @@ -100,7 +100,7 @@ to the logger::

class ApplicationComponent(CLIApplicationComponent):
async def run(self, ctx):
with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession() as session:
last_modified, old_lines = None, None
while True:
logger.debug('Fetching webpage')
Expand Down Expand Up @@ -150,7 +150,7 @@ And to make the the results look nicer in an email message, you can switch to us
await super().start(ctx)

async def run(self, ctx):
with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession() as session:
last_modified, old_lines = None, None
diff = HtmlDiff()
while True:
Expand Down Expand Up @@ -223,7 +223,7 @@ Next, add another class in the same module that will do the HTTP requests and ch
self.delay = delay

async def run(self):
with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession() as session:
last_modified, old_lines = None, None
while True:
logger.debug('Fetching contents of %s', self.url)
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial2/webnotifier/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, url, delay):
self.delay = delay

async def run(self):
with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession() as session:
last_modified, old_lines = None, None
while True:
logger.debug('Fetching contents of %s', self.url)
Expand Down

0 comments on commit 390b7fd

Please sign in to comment.