Created
January 21, 2023 02:53
-
-
Save stugmi/5c7470c961107ddf46ed2d2928afff84 to your computer and use it in GitHub Desktop.
print core list with option to exclude hyperthread cores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from subprocess import Popen, PIPE | |
| def lscpu(show_hyperthreads: bool = True) -> list: | |
| cmd = "lscpu -a -e".split() | |
| stdout, stderr = Popen(cmd, stdout=PIPE).communicate() | |
| out = stdout.decode().split("\n") | |
| header = out[0].split() | |
| cores = [dict(zip(header, row.split())) for row in out[1:-1]] | |
| if not show_hyperthreads: | |
| return cores[::2] # every other | |
| return cores | |
| if __name__ == "__main__": | |
| from rich import print # pip install rich | |
| cores = lscpu(show_hyperthreads=False) | |
| print(cores) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment