# 记录一些日志信息 logger.debug('This is a debug message') logger.info('This is an info message') logger.warning('This is a warning message') logger.error('This is an error message') logger.critical('This is a critical message')
# 记录日志信息 logging.debug('This is a debug message.') logging.info('This is an info message.') logging.warning('This is a warning message.') logging.error('This is an error message.') logging.critical('This is a critical message.')
for partition in disk_partitions: print(f"Device: {partition.device}, Mount Point: {partition.mountpoint}")
# 获取磁盘使用情况 disk_usage = psutil.disk_usage('/') print(f"Total Disk Space: {disk_usage.total} bytes") print(f"Used Disk Space: {disk_usage.used} bytes") print(f"Free Disk Space: {disk_usage.free} bytes") print(f"Disk Usage Percentage: {disk_usage.percent}%")
获取网络信息:
1 2 3 4 5 6 7 8 9 10 11 12
# 获取网络接口信息 net_interfaces = psutil.net_if_addrs()
for interface, addresses in net_interfaces.items(): print(f"Interface: {interface}") for address in addresses: print(f" - Address Family: {address.family}, Address: {address.address}")
# 获取网络连接信息 net_connections = psutil.net_connections(kind='inet') for conn in net_connections: print(f"Local Address: {conn.laddr}, Remote Address: {conn.raddr}, Status: {conn.status}")
for i inrange(5): event = threading.Event() events.append(event) t = threading.Thread(target=worker, args=(f"Thread-{i}", i, event)) threads.append(t) t.start()
pattern = r'apple' text = "I like apples." match = re.search(pattern, text) ifmatch: print("Match found:", match.group()) else: print("No match found.")
pattern = r'apple' text = "apple pie is delicious." match = re.match(pattern, text) ifmatch: print("Match found:", match.group()) else: print("No match found.")