title: Why is this Jupyter cell executing ahead of asynchronous loop cell?
body: <p>I'm trying to send 6 API requests in one session and record how long it took.  Do this n times.  I store the amount of time in a list.  After that I print out some list info and visualize the list data.</p>
  
  <ol>
  <li>What works: downloading as .py, removing ipython references, and running the code as a command line script.</li>
  <li>What also works: manually running the cells, and the erroring cell after the loop cell completes.</li>
  <li>What doesn't work: restarting and running all cells within the jupyter notebook.  The last cell seems to not wait for the prior one; the latter appears to execute first, and complain about an empty list.  Error in image below.</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/YBmPs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YBmPs.png" alt="enter image description here"></a></p>
  
  <p>Cell 1:</p>
  
  <pre><code># submit 6 models at the same time
  # using support / first specified DPE above
  auth = aiohttp.BasicAuth(login=USERNAME, password=API_TOKEN)
  
  async def make_posts():
      for i in range(0, 6):
          yield df_input['deployment_id'][i]
  
  async def synch6():
      #url = "%s/predApi/v1.0/deployments/%s/predictions" % (PREDICTIONSENDPOINT,DEPLOYMENT_ID)
      async with aiohttp.ClientSession(auth=auth) as session:
          post_tasks = []
          # prepare the coroutines that post
          async for x in make_posts():
              post_tasks.append(do_post(session, x))
          # now execute them all at once
          await asyncio.gather(*post_tasks)
  
  
  async def do_post(session, x):
      url = "%s/predApi/v1.0/deployments/%s/predictions" % (PREDICTIONSENDPOINT, x)
      async with session.post(url, data = df_scoreme.to_csv(), headers=PREDICTIONSHEADERS_csv) as response:
          data = await response.text()
          #print (data)
  
  </code></pre>
  
  <p>Cell 2:</p>
  
  <pre><code>chonk_start = (datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.000Z"))
  
  perf1 = []
  n = 100
  
  for i in range(0, n):
      start_ts = round(time.time() * 1000)
      loop = asyncio.get_event_loop()
      loop.run_until_complete(synch6())
      end_ts = round(time.time() * 1000)
      perf1.append(end_ts - start_ts)
  
  </code></pre>
  
  <p>Cell 3:</p>
  
  <pre><code>perf_string(perf1, 'CHONKS')
  </code></pre>
  
  <p>The explicit error (see image) appears to simply be the result of trying to work on an empty list.  The list appears to be empty because that cell is executing before the loop test cell actually populates the list - although I don't know why.  This appears to only be a problem inside the notebook.</p>
  
  <p>EDIT: In further testing...  this appears to work fine on my local (python3, mac) jupyter notebook.  Where it is failing is on a AWS Sagemaker conda python3 notebook.</p>