2

I have some Python code that I want to debug with perf. Now, the thing with perf is that it gives the output when the process is terminated, I want to do the same via a Python script.

perf stat -p <my_pid>

I want to run this inside a Python code in background, until some point where I want to be able to terminate its operation and print the commands output. To show what I mean:

x = subprocess.Popen(["perf","stat","-p",str(GetMyProcessID())], stdout = subprocess.PIPE)

.. CODE TO DEBUG ..

#Terminate the process and get the output after ??

Is something like this possible ?

EDIT: This is not a duplicate question, I have tried to refine my question and its title as I have more clear understanding about it right now.

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
mozcelikors
  • 2,582
  • 8
  • 43
  • 77
  • Possible duplicate of [Python subprocess running in background before returning output](http://stackoverflow.com/questions/41654499/python-subprocess-running-in-background-before-returning-output) – Maurice Meyer Jan 15 '17 at 18:48
  • You could link stdout to a log file, and the print the contents out later. – cs95 Jan 15 '17 at 18:58
  • Do you have any link to guide me how to do it? – mozcelikors Jan 15 '17 at 19:07

0 Answers0