title: Get data from process
body: <p>Suppose I have a python script program.py
  that looks as follows:</p>
  <pre><code># program.py
  import random
  class Program
      def __init__(self):
          self.data = []
      def run():
          while True:
              self.data.append(random.random()]
  
  if __name__ == &quot;__main__&quot;:
      program = Program()
      program.run()
  </code></pre>
  <p>Now suppose that I have another script script.py that calls program.py as a separate process.</p>
  <pre><code># script.py
  import subprocess
  import time
  
  process = subprocess.Popen([&quot;py&quot;, &quot;program.py&quot;])
  while True:
      data = get_program_data(process)# how?
      time.sleep(10)
  </code></pre>
  <p>The purpose of script.py is to illustrate the fact that I don't have access to the class Program. In my case this is due to the fact that I will be triggering program.py from a .NET application. I thought I'll try to understand how to deal with this problem from a python script first then apply it to the .NET application. So here is my question (keep in mind that I can alter the code in program.py and script.py, but script.py can not access program.py):</p>
  <p>How should I go about accessing self.data from the process? I have been searching all over and I'm not quite sure in what direction I should be going. In my case, I will need to trigger difference commands for different ind of data generated in Program, i.e. get_program_data1(), get_program_data2(),....</p>
  <p>The way I have been &quot;solving&quot; this issue is to have a file controller.json that script.py modifies and program.py reads and acts accordingly. I does not feel quite right doing and so I want your opinion about this. Remember that ultimately, script.py is a .NET application. Thanks</p>