- #1
zak100
- 462
- 11
- TL;DR Summary
- I am trying to display system information. I found some commands but I am getting a sytax error
Hi,
I am getting following error message:
I have written the following code which should display the system information of a simple program which I am running as a function:
Somebody please guide me how to solve this problem.
Zulfi.
I am getting following error message:
Traceback (most recent call last):
File "/home/zulfi/PycharmProjects/Classes/psutilPrintInfo.py", line 31, in <module>
obj_Counting_SysInfo.main()
File "/home/zulfi/PycharmProjects/Classes/psutilPrintInfo.py", line 27, in main
self.system_info()
File "/home/zulfi/PycharmProjects/Classes/psutilPrintInfo.py", line 16, in system_info
mem = process.get_memory_info()[0] / float(2 ** 30) # memory in GB
AttributeError: 'Process' object has no attribute 'get_memory_info'
I have written the following code which should display the system information of a simple program which I am running as a function:
Python:
import psutil
import osclass Counting_SysInfo:
def __init__(self, i):
self.i = i def Print_Numbers(self):
for i in range(50):
print (i) def system_info(self):
# return the memory usage in MB
self.Print_Numbers()
process = psutil.Process(os.getpid())
mem = process.get_memory_info()[0] / float(2 ** 30) # memory in GB
cpu = process.cpu_percent() / psutil.cpu_count()
disk = process.disk_usage(part.mountpoint).percent # https://github.com/giampaolo/psutil/blob/master/scripts/disk_usage.py
vMem = int(process.virtual_memory().available)
print(process.memory_info().rss) # in bytes
RSS = process.memory_info().rss
# https://stackoverflow.com/questions/17990227/whats-the-unit-of-rss-in-psutil-process-get-memory-info
pageFaults = process.memory_info().pfaults # https://readthedocs.org/projects/giamptest/downloads/pdf/latest/
print("mem= ", mem, "cpu= ", cpu, 'disk= ',disk, "VMem= ", vMem, "RSS= ", RSS, "page faults=", pageFaults ) def main(self):
self.system_info()if __name__ == "__main__":
obj_Counting_SysInfo = Counting_SysInfo(10)
obj_Counting_SysInfo.main()
Somebody please guide me how to solve this problem.
Zulfi.