title: how do I create a generator for shell communication in python?
body: <p>I want to create a generator for communicating with processes through the shell.
  So far what I have is this: </p>
  
  <pre class="lang-py prettyprint-override"><code>def shell():
      with Popen(["bash"], stdout=PIPE, stdin=PIPE) as p:
          while True:
              yield p.communicate(str.encode((yield)))[0]
  
  </code></pre>
  
  <p>That of course has two problems.</p>
  
  <ul>
  <li>it crashes very easily</li>
  <li>the communication is weird since there are two yields for every iteration of the <code>while</code> loop</li>
  </ul>
  
  <p>Any ideas?</p>