@@ -124,35 +124,53 @@ def ram_total(convert=True):
124124 :type convert:bool
125125 :return: total ram of board as string
126126 '''
127- response = list (psutil .virtual_memory ())
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())
128134 if convert == True :
129- return convert_bytes (response [ 0 ])
135+ return convert_bytes (splited_response [ 7 ])
130136 else :
131- return str (response [ 0 ])
137+ return str (splited_response [ 7 ])
132138def ram_used (convert = True ):
133139 '''
134140 Return how much ram is using
135141 :param convert: Flag for convert mode (using of convert_byte function)
136142 :type convert:bool
137143 :return: how much ram is using as string
138144 '''
139- response = list (psutil .virtual_memory ())
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())
140152 if convert == True :
141- return convert_bytes (response [ 3 ])
153+ return convert_bytes (splited_response [ 8 ])
142154 else :
143- return str (response [ 3 ])
155+ return str (splited_response [ 8 ])
144156def ram_free (convert = True ):
145157 '''
146158 Return how much ram is available
147159 :param convert: Flag for convert mode (using of convert_byte function)
148160 :type convert : bool
149161 :return: how much ram is available
150162 '''
151- response = list (psutil .virtual_memory ())
152- if convert == True :
153- return convert_bytes (response [1 ])
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())
170+ if convert == True :
171+ return convert_bytes (splited_response [9 ])
154172 else :
155- return str (response [ 1 ])
173+ return str (splited_response [ 9 ])
156174def ram_percent ():
157175 '''
158176 Return available ram percentage
0 commit comments