@@ -124,53 +124,35 @@ def ram_total(convert=True):
124
124
:type convert:bool
125
125
:return: total ram of board as string
126
126
'''
127
- command = sub .Popen (["free" ,"-m" ],stdout = sub .PIPE ,stderr = sub .PIPE ,stdin = sub .PIPE )
128
- response = list (command .communicate ())[0 ]
129
- splited_response = str (response ).split (" " )
130
- for i in splited_response :
131
- if i == "" :
132
- splited_response .remove (i )
133
- #response=list(psutil.virtual_memory())
127
+ response = list (psutil .virtual_memory ())
134
128
if convert == True :
135
- return convert_bytes (splited_response [ 7 ] )
129
+ return convert_bytes (int ( response [ 0 ]) )
136
130
else :
137
- return str (splited_response [ 7 ])
131
+ return str (response [ 0 ])
138
132
def ram_used (convert = True ):
139
133
'''
140
134
Return how much ram is using
141
135
:param convert: Flag for convert mode (using of convert_byte function)
142
136
:type convert:bool
143
137
:return: how much ram is using as string
144
138
'''
145
- command = sub .Popen (["free" , "-m" ], stdout = sub .PIPE , stderr = sub .PIPE , stdin = sub .PIPE )
146
- response = list (command .communicate ())[0 ]
147
- splited_response = str (response ).split (" " )
148
- for i in splited_response :
149
- if i == "" :
150
- splited_response .remove (i )
151
- # response=list(psutil.virtual_memory())
139
+ response = list (psutil .virtual_memory ())
152
140
if convert == True :
153
- return convert_bytes (splited_response [ 8 ] )
141
+ return convert_bytes (int ( response [ 3 ]) )
154
142
else :
155
- return str (splited_response [ 8 ])
143
+ return str (response [ 3 ])
156
144
def ram_free (convert = True ):
157
145
'''
158
146
Return how much ram is available
159
147
:param convert: Flag for convert mode (using of convert_byte function)
160
148
:type convert : bool
161
149
:return: how much ram is available
162
150
'''
163
- command = sub .Popen (["free" , "-m" ], stdout = sub .PIPE , stderr = sub .PIPE , stdin = sub .PIPE )
164
- response = list (command .communicate ())[0 ]
165
- splited_response = str (response ).split (" " )
166
- for i in splited_response :
167
- if i == "" :
168
- splited_response .remove (i )
169
- # response=list(psutil.virtual_memory())
151
+ response = list (psutil .virtual_memory ())
170
152
if convert == True :
171
- return convert_bytes (splited_response [ 9 ] )
153
+ return convert_bytes (int ( response [ 1 ]) )
172
154
else :
173
- return str (splited_response [ 9 ])
155
+ return str (response [ 1 ])
174
156
def ram_percent ():
175
157
'''
176
158
Return available ram percentage
0 commit comments