ITADN

Possible memory leak in read_loop

#247Closedtepiloxtl 创建于 2026-01-20
T
tepiloxtlcommented
Minimal code triggering the leak: ``` import evdev import time # import tracemalloc # tracemalloc.start() def main(): # lastsec = 0 device = evdev.InputDevice('/dev/input/event2') #mouse with high polling rate for event in device.read_loop(): if event.type == evdev.ecodes.EV_KEY: #this keeps loop going while avoiding spamming output with movement events print(event) # timenow = int(time.time()) # if timenow % 10 == 0 and timenow != lastsec: # lastsec = timenow # snapshot = tracemalloc.take_snapshot() # top_stats = snapshot.statistics('lineno') # print(f"--- Memory at {timenow} ---") # for stat in top_stats[:3]: # print(stat) if __name__ == "__main__": main() ``` Running this code, making big random mouse movements and observing memory usage, in my case I observer usage going up by 1MB every couple seconds. By uncommenting tracemalloc code you can see usage statistics where this steadily gains more lineno count and mem usage: `.../.venv/lib64/python3.14/site-packages/evdev/eventio.py:71: size=3162 KiB, count=101113, average=32 B` python-evdev version: ``` $ pip list installed | grep evdev evdev 1.9.2 ``` I'm not sure if I'm doing this right, or if the problem is in this code or something else I'm doing. In my project I had a go at replacing the reading loop with directly interacting with event files and that seemed to ease out memory allocation problem, but I have not thoroughly tested that change yet, I'm yet to say if the functionality is 1:1 with the evdev code
关闭于 2026-02-05 2 条评论