title: nested "async with" using aiohttp
body: <p>I would like to create a scheduler class that uses aiohttp to make API calls. I tried this:</p>
  <pre><code>import asyncio
  import aiohttp
  
  class MySession:
      def __init__(self):
          self.session = None
  
      async def __aenter__(self):
          async with aiohttp.ClientSession() as session:
              self.session = session
              return self
  
      async def __aexit__(self, exc_type, exc_val, exc_tb):
          if self.session:
              await self.session.close()
  
  async def method1():
      async with MySession() as s:
          async with s.session.get(&quot;https://www.google.com&quot;) as resp:
              if resp.status == 200:
                  print(&quot;successful call!&quot;)
  
  loop = asyncio.get_event_loop()
  loop.run_until_complete(method1())
  loop.close()
  </code></pre>
  <p>but this just results in an error: <code>RuntimeError: Session is closed</code>.</p>
  <p>A second approach for the <code>__aenter__</code> function:</p>
  <pre><code>    async def __aenter__(self):
          self.session = aiohttp.ClientSession()
          return self
  </code></pre>
  <p>works well. Is this a good construct? It doesn't adhere to examples of how to use aiohttp. Also wondering why the first approach isn't working?</p>