Python Technical Tips for System Monitoring and Communication

1. Time Handling in PyQt5

To retrieve the current system time within a PyQt5 application, use the QDateTime.currentDateTime() method. This provides a Qt-specific way to access date and time information. Alternatively, the standard Python datetime module can also be used.

2. System Performance Monitoring

The psutil module allows developers to monitor various system performance metrics:

  • psutil.boot_time(): Returns the system boot time as a Unix timestamp.
  • psutil.virtual_memory(): Provides detailed memory usage statistics including total, available, and used memory values.

3. Network Connectivity Testing

For network testing purposes, the ping3 module can be used to send ICMP echo requests:

  • ping3.ping(host): Sends a ping request to the specified host and returns the round-trip delay in seconds as a float, which can be converted to milliseconds by multiplying by 1000.

4. ZeroMQ Communication Setup

ZeroMQ (ZMQ) is a high-level messaging library useful for inter-process and network communication. Below is a basic example of a publish-subscribe pattern:

Subscriber Client


import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect("tcp://127.0.0.1:10086")
socket.setsockopt_string(zmq.SUBSCRIBE, "")

print("Subscriber connected")
while True:
    message = socket.recv_pyobj()
    print(f"Received: {message}")
    time.sleep(1)

Publisher Server


import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:10086")

print("Publisher started")
while True:
    socket.send_pyobj("Hello World")
    time.sleep(1)

5. Video Stream Handling

Video streams can be captured and processed using the imutils and cv2 modules:

Capturing and Sending Video Frames


from imutils.video import VideoStream
from collections import deque

stream_url = "rtsp://username:password@ip_address:port/stream"
video_stream = VideoStream(stream_url).start()
frame_buffer = deque(maxlen=10)

while True:
    frame = video_stream.read()
    frame_buffer.append(frame)

Receiving and Displaying Video Frames


from collections import deque
import cv2
from PyQt5 import QtGui

frame_buffer = deque()
if len(frame_buffer) > 0:
    raw_frame = frame_buffer.popleft()
    rgb_frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2RGB)
    height, width, channel = rgb_frame.shape
    q_image = QtGui.QImage(rgb_frame.data, width, height, rgb_frame.strides[0], QtGui.QImage.Format_RGB888)
    q_image = q_image.scaled(self.display_width, self.display_height)
    self.image_label.setPixmap(QtGui.QPixmap.fromImage(q_image))

6. Retrieving Screen Resolution

To get the current screen resolution in a Windows environment using Python:


import ctypes

user32 = ctypes.windll.user32
screen_width = user32.GetSystemMetrics(0)
screen_height = user32.GetSystemMetrics(1)
resolution = (screen_width, screen_height)

Tags: PyQt5 psutil ping3 ZeroMQ OpenCV

Posted on Sun, 17 May 2026 02:42:46 +0000 by toasty2