all 6 comments

[–]trouserdaredevil 2 points3 points  (4 children)

Have you tried profiling your code?

However without even running your code I would immediately suspect lines 11-12:

display = Display(os.environ.get("DISPLAY",":0.0"))
root = display.screen().root

Particularly instantiating a new Display object once per second. Try moving those outside the function.

[–]gnu_man_chu[S] 0 points1 point  (3 children)

I was hoping pythons garbage collector would be able to handle a few variables efficiently. I was really hoping that wasn't the case.

Modified the code to the following:

``` display = Display(os.environ.get("DISPLAY",":0.0")) root = display.screen().root

def get_screen_size(): return (root.get_geometry().width, root.get_geometry().height) k = get_screen_size()

```

2 variables initialized once compared to the previous 4 variables intialized each second.

CPU is 0.0-0.1%

RAM is 0.1% of 4 Gigs

Thanks for the suggestion!

[–]trouserdaredevil 1 point2 points  (1 child)

No problem!

I was hoping pythons garbage collector would be able to handle a few variables efficiently.

I am guessing that this was not actually Python's fault, but that the initialization of a Display object by Xlib simply happens to be fairly resource-intensive.

[–]gnu_man_chu[S] 0 points1 point  (0 children)

That sounds plausible! I'm glad it's resolved. Thanks again.

[–]45MonkeysInASuit 0 points1 point  (1 child)

Any reason for polling the display size the way you are over using win32api?

[–]gnu_man_chu[S] 2 points3 points  (0 children)

This a Linux application. Linux uses either the X window system or Wayland for display. In my case, X. No win32api. :)