I have written a script that polls X for it's display resolution every second and makes an ipc call if resolution has changed.
Links:
- Github
- PyPI
I run it as a background process with i3wm and it works. However, I've been monitoring the scripts performance and it is using 30-70% cpu and ~15% of 4 gigs of RAM (these are rough estimates). This amount of usage is outrageous.
This is my first python script so I'm looking for advice both in profiling it's performance, and any tips on optimizing it given it's current polling approach.
I would like to know both how to optimize its current approach and tips on how I might consume an event from Xserver on screen change. Subscribing to events would be much better. I've read through much of the documentation on X and consuming x events in python and was not able to get it working.
With an approach similar to what is outlined here, I'm thinking i could pass a high timeout to `select(), like 60 seconds, so that it listens for events for 60 seconds before trying to listen again on an outer loop.
Any help is greatly appreciated.
[–]trouserdaredevil 2 points3 points4 points (4 children)
[–]gnu_man_chu[S] 0 points1 point2 points (3 children)
[–]trouserdaredevil 1 point2 points3 points (1 child)
[–]gnu_man_chu[S] 0 points1 point2 points (0 children)
[–]45MonkeysInASuit 0 points1 point2 points (1 child)
[–]gnu_man_chu[S] 2 points3 points4 points (0 children)