title: subprocess.run() get pid of the process
body: <p>I want to run a program from inside my Python script and get the PID of the process I launched. I tried with :
  <code>p=subprocess.Popen(nameofmyprocess) pid=p.pid</code>
  But the problem is that it doesn't wait for my called program to finish. When I looked at the documentation, I concluded I should use <code>subprocess.run()</code> instead, however it doesn't have a <code>.pid</code> like <code>Popen</code>
  Is there another alternative ?</p>
  <p><strong>Edit :</strong>
  I should have mentioned this in the original question. The code of my program includes a server part where it opens a socket and listens to it. I have a client side which connects to that socket and sends a message. My end goal is to write a script that runs my program, gets its PID to pass it to some functions I wrote that will do the monitoring of my program : they will show me the memory usage of my program, the socket it has opened, the file descriptors.. basically information about things my program does.
  As suggested , I used <code>subprocess.Popen.poll</code> so now my code looks like this :</p>
  <pre><code>p=subprocess.Popen(nameofmyprocess) 
  pid=p.pid
  print pid
  while (p.poll() is None):
     time.sleep(20)
     myFunc(pid)
     myFunc2(pid)
  </code></pre>
  <p>However, when I run this script and run my client, it can't connect to my server program. It says &quot;Connection failed&quot;. I'm pretty sure the program is running though because the PID I print is displayed when I use the command <code>ps aux</code> on another terminal.</p>