Modify psutil.net_connections() to retrieving unnecessary connection types unless explicitly asked. E.g., on an IDLE system with few IPv6 connections this will run around 170% faster:
import psutil, time
started = time.monotonic()
for x in range(1000):
psutil.net_connections("tcp6")
print(f"completed in {(time.monotonic() - started):.4f} secs")
Before all connection types (TCP, UDP, UNIX) were retrived internally, even if they were not returned.
Summary
Description
Modify
psutil.net_connections()
to retrieving unnecessary connection types unless explicitly asked. E.g., on an IDLE system with few IPv6 connections this will run around 170% faster:Before all connection types (TCP, UDP, UNIX) were retrived internally, even if they were not returned.