title: python asyncio run event loop once?
body: <p>I am trying to understand the asyncio library, specifically with using sockets. I have written some code in an attempt to gain understanding, </p>
  
  <p>I wanted to run a sender and a receiver sockets asynchrounously. I got to the point where I get all data sent up till the last one, but then I have to run one more loop. Looking at how to do this, I found <a href="https://stackoverflow.com/questions/29782377/is-it-possible-to-run-only-a-single-step-of-the-asyncio-event-loop">this link from stackoverflow</a>, which I implemented below -- but what is going on here? Is there a better/more sane way to do this than to call <code>stop</code> followed by <code>run_forever</code>?</p>
  
  <p>The documentation for <code>stop()</code> in the event loop is:</p>
  
  <blockquote>
    <p>Stop running the event loop.</p>
    
    <p>Every callback scheduled before stop() is called will run. Callbacks scheduled after stop() is called will not run. However, those callbacks will run if run_forever() is called again later.</p>
  </blockquote>
  
  <p>And <code>run_forever()</code>'s documentation is:</p>
  
  <blockquote>
    <p>Run until stop() is called.</p>
  </blockquote>
  
  <p>Questions:</p>
  
  <ul>
  <li>why in the world is <code>run_forever</code> the only way to <code>run_once</code>? This doesn't even make sense</li>
  <li>Is there a better way to do this?</li>
  <li>Does my code look like a reasonable way to program with the asyncio library? </li>
  <li>Is there a better way to add tasks to the event loop besides <code>asyncio.async()</code>? <code>loop.create_task</code> gives an error on my Linux system.</li>
  </ul>
  
  <p><a href="https://gist.github.com/cloudformdesign/b30e0860497f19bd6596" rel="nofollow noreferrer">https://gist.github.com/cloudformdesign/b30e0860497f19bd6596</a></p>