@@ -124,53 +124,35 @@ def ram_total(convert=True):
124124 :type convert:bool
125125 :return: total ram of board as string
126126 '''
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 ())
134128 if convert == True :
135- return convert_bytes (splited_response [ 7 ] )
129+ return convert_bytes (int ( response [ 0 ]) )
136130 else :
137- return str (splited_response [ 7 ])
131+ return str (response [ 0 ])
138132def ram_used (convert = True ):
139133 '''
140134 Return how much ram is using
141135 :param convert: Flag for convert mode (using of convert_byte function)
142136 :type convert:bool
143137 :return: how much ram is using as string
144138 '''
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 ())
152140 if convert == True :
153- return convert_bytes (splited_response [ 8 ] )
141+ return convert_bytes (int ( response [ 3 ]) )
154142 else :
155- return str (splited_response [ 8 ])
143+ return str (response [ 3 ])
156144def ram_free (convert = True ):
157145 '''
158146 Return how much ram is available
159147 :param convert: Flag for convert mode (using of convert_byte function)
160148 :type convert : bool
161149 :return: how much ram is available
162150 '''
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 ())
170152 if convert == True :
171- return convert_bytes (splited_response [ 9 ] )
153+ return convert_bytes (int ( response [ 1 ]) )
172154 else :
173- return str (splited_response [ 9 ])
155+ return str (response [ 1 ])
174156def ram_percent ():
175157 '''
176158 Return available ram percentage
0 commit comments