jetson_stats
jetson_stats copied to clipboard
Jetson stats not working with python subprocess module
I have to run my application binary and get the jtop data into a csv file while running the app. So I have written this code to do the same . But the issue is that when I am running it the script automatically exits in sometime and it is not running for the duration given. Sharing the code below:
from jtop import jtop
import csv
import subprocess
import sys
""" Function to export jtop data to csv file """ def export_data(): print("Exporting jtop data to csv")
with jtop() as jetson:
# boards
print('*** board ***')
print(jetson.board)
print('Execution time 60sec approx')
csvfile = open('Output_data.csv','w')
writer = csv.DictWriter(csvfile,fieldnames=jetson.stats.keys())
writer.writeheader()
writer.writerow(jetson.stats)
start_time=jetson.stats['time']
# jetson.ok() will provide the proper update frequency
while jetson.ok():
curr_time=jetson.stats['time']
if(str(curr_time-start_time) >= '0:00:90.620888'):
print(str(curr_time-start_time))
print("Script_Exit")
break
else:
print("Script_Running")
print(str(curr_time-start_time))
writer.writerow(jetson.stats)
csvfile.close()
""" Function to execute binary and export function using subprocess module """ def Execute_bin(): command="./My_App.bin" processWorkingDir="....../path/"
process = subprocess.Popen(command, cwd=processWorkingDir )
print("\n##############################################################\n")
export_data()
print("\n##############################################################\n")
process.kill()
if name == "main":
Execute_bin()
EOF
If I am running the application binary and jetson stats python script seperatly in two different terminals then it is working fine . But while running in one terminal using subprocess it exits automatically after sometime. Not getting where is the issue.