title: Passing data between 2 endless loops in python
body: <p>I am using a python script which uses cmdloop and takes input from the commandline:</p>
  <pre><code>import cmd
  
  
  class SuperC2(cmd.Cmd):
      def default(self, line):
          f = open(&quot;command.txt&quot;, &quot;w&quot;)
          f.write(line)
          f.close()
  
  
  if __name__ == '__main__':
      SuperC2().cmdloop('Shell')
  </code></pre>
  <p>Another script uses flask and reads the command.txt file and serves it (via GET request) to a client. It also listens for POSTs of clients that executed this command and posted the output:</p>
  <pre><code>from flask import Flask
  from flask import request
  
  app = Flask(__name__)
  
  
  @app.route('/command')
  def command():
      str = open('command.txt', 'r').read()
      return str
  
  @app.route('/result', methods = ['POST'])
  def result():
  
      if request.method == 'POST':
          data = request.form
          print(data[&quot;command&quot;])
          print(data[&quot;output&quot;])
      return &quot;ok&quot;
  
  if __name__ == '__main__':
      app.run(host='0.0.0.0', port=8000)
  </code></pre>
  <p>What I really would like to achieve is to have 1 script that runs the flask app and the cmdloop at the same time, with only the cmdloop showing the command and the result (it got from the flask POSTs). Can someone give an example on how it can be done? I'm guessing Process Queues or pipes?</p>