Lisias Posted 4 hours ago Share Posted 4 hours ago (edited) This is the 3rd article of a series aiming to allow you to run KSP on crappy potatoes! Recently, Fellow Kerbonaut @Linkageless published an article about how to prevent KSP from overloading you rig when you are not playing, for example when you pause it to look for something on the web. Pretty useful, indeed. But then I thought to myself (I do these things now and then... ) "Heck, I can use it to prevent other programs from screwing KSP too!!", and then I build this Python tool: Window Monitor. It essentially monitors the Window currently in focus and compare its name with a internal table of "Applications of Interest". When one of these AOI gets the Focus, the tool will unpause it using a special (and unprivileged) Operating System tool, and will pause all the others in that table: essentially, you define a set of mutually exclusive running programs so only one of them would be using CPU (and RAM) at a time! This little hack made my life immensely easier on my rig - I usually have tons of tabs opened on my browser, and since nowadays every single damned page you open in your browser fires many tools in the background (be to spy on you, be to receive notifications, be by any other reason - or all of them, they are not mutually exclusive!) and this ton of crap have two nasty effects on your rig: It steals CPU, leaving less juice available for KSP. 50% of CPU usage sometimes... I prevents these processes' RAM to swap, and so KSP need to compete heavily for the available RAM! Last time I cared about, Firefox was using about 7G of RAM. By pausing my browser, all the tabs will just had their execution frozen - and eventually the Operating System will swap them into the swapfile giving my more RAM to use on KSP - and no need to stop/unstop the JavaScript runtime all time neither. Sweat! However... There's no free lunch: if you focus one of the browser's Windows, the focused Application's processes will take some time to come back from the freezer: it's almost sure that a good part (if not all) of the process' memory was swapped and then it must be bought back and with KSP now on the freezer too, it will be swapped to the disk in the process. So this can take some some time, almost a minute if you are still using spinning platters as storage. You will not be able to watch videos or listen music from your browser neither - for me this is not a problem, because I use VLC and IceCast for streaming, but sometimes I just want to check a quick video on Facebook or give a peek on Forum while KSP is busy doing something lengthy, but switching will pause the game defeating the purpose of the action at first place. Obviously, you can just quit the tool for that - it will unpause any paused applications before quitting, and you can always run it again after. The program have currently the following caveats: Needs Python installed. I suggest 3.11, but I think that anything from 3.7 and above will work. And you will need to install some libraries too. I implemented support only for MacOS for now. Linux and Windows will be implemented during the week, assuming nothing explodes around here on DayJob©. The program is still dumb as a door - it blindly pauses and unpauses the registered Applications, disregarding if they are running or not. Annoying, but harmless. You can just delete one or more of the lines mentioning the Applications not installed, or that you don't want to freeze. And you can easily add others if you want (and know how to do it). No GUI support yet. You will need to run it from a Terminal or Console. I will write one, but not before implementing support for Linux and Windows. Hit CTRL-C on the Terminal running the tool to finish it. DO NOT CLOSE THE TERMINAL neither KILL the process, or it will not unpause the paused Applications! But you can always run it again to fix the mess, so no big deal. No installer. Download the thing manually, or just clone the whole repo for now. Follows a execution log from the tool while I was testing it: (3.11) lisias@macmini62 ~/Workspaces/KSP/GIT/net-lisias/ksp/KSP-Hacks/utils > ./window_monitor.py 2025-03-10 01:16:22: Running on posix : Darwin : 18.7.0 2025-03-10 01:16:22: Focused iTerm2 [/Applications/Utilities/iTerm.app] 2025-03-10 01:16:22: Pausing Firefox 2025-03-10 01:16:22: Pausing Kerbal Space Program 2025-03-10 01:16:25: Focused Kerbal Space Program [/Users/lisias/Applications/Games/KSP/Random.143/KSP.app] 2025-03-10 01:16:25: Unpausing Kerbal Space Program 2025-03-10 01:18:08: Focused Firefox [/Applications/Firefox.app] 2025-03-10 01:18:08: Pausing Kerbal Space Program 2025-03-10 01:18:08: Unpausing Firefox 2025-03-10 01:50:08: Focused Kerbal Space Program [/Users/lisias/Applications/Games/KSP/Random.143/KSP.app] 2025-03-10 01:50:08: Pausing Firefox 2025-03-10 01:50:08: Unpausing Kerbal Space Program 2025-03-10 04:32:16: Focused Firefox [/Applications/Firefox.app] 2025-03-10 04:32:17: Pausing Kerbal Space Program 2025-03-10 04:32:18: Unpausing Firefox 2025-03-10 05:18:57: Focused iTerm2 [/Applications/Utilities/iTerm.app] 2025-03-10 05:18:57: Pausing Firefox KeyboardInterrupt 2025-03-10 05:19:03: Exiting!!! Restoring any paused applications... 2025-03-10 05:19:03: Unpausing Firefox 2025-03-10 05:19:03: Unpausing Kerbal Space Program Dependencies: MacOS port install gobject-introspection I use MacPorts, but this is available also on Brew. pip install pyobjc I strongly recommend creating a Virtual Environment (venv) for running this tool. Linux WiP Windows WiP Freeze Safe!!!! Edited 2 hours ago by Lisias Entertaining grammars made slightely less entertaining... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.