Skip to content

Commit

Permalink
Adds a note on auto-restarted X servers
Browse files Browse the repository at this point in the history
  • Loading branch information
andyljones committed Oct 16, 2019
1 parent e0837c1 commit d5d081f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions coolgpus
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ I can't claim it's optimal, but it Works For My Machine (TM). Full load is about
parser.add_argument('--temp', nargs=2, default=[55, 80], type=float, help='The temperature range where the fan speed will increase linearly')
parser.add_argument('--speed', nargs=2, default=[30, 99], type=float, help='The minimum and maximum fan speeds')
parser.add_argument('--hyst', nargs='?', default=2, type=float, help='The hysteresis gap. Large gaps will reduce how often the fan speed is changed, but might mean the fan runs faster than necessary')
parser.add_argument('--kill', action='store_true', default=False, type=bool, help='Whether to kill existing Xorg sessions')
parser.add_argument('--kill', action='store_true', default=False, help='Whether to kill existing Xorg sessions')
args = parser.parse_args()

T_MIN, T_MAX = args.temp
Expand Down Expand Up @@ -76,15 +76,15 @@ Section "Monitor"
EndSection
"""

def log_output(command):
def log_output(command, ok=(0,)):
output = []
try:
p = Popen(command, stdout=PIPE, stderr=STDOUT)
for line in p.stdout:
output.append(line.decode().strip())
p.wait()
finally:
if p.returncode != 0:
if p.returncode not in ok:
print('\n'.join(output))
raise ValueError('Command ' + ' '.join(command) + ' crashed with return code ' + str(p.returncode) + ':')
return '\n'.join(output)
Expand Down Expand Up @@ -125,7 +125,7 @@ def xserver(display, bus):
return p

def xserver_pids():
return list(map(int, log_output(['pgrep', 'Xorg']).splitlines()))
return list(map(int, log_output(['pgrep', 'Xorg'], ok=(0, 1)).splitlines()))

def kill_xservers():
"""If there are already X servers attach to the GPUs, they'll stop us from setting up our own. Right now we
Expand All @@ -135,10 +135,11 @@ def kill_xservers():
if servers:
if args.kill:
print('Killing all running X servers, including ' + ", ".join(map(str, servers)))
log_output(['pkill', 'Xorg'])
log_output(['pkill', 'Xorg'], ok=(0, 1))
for _ in range(10):
if xserver_pids():
print('Awaiting X server shutdown')
time.sleep(1)
else:
print('All X servers killed')
return
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ sudo systemctl start coolgpus
```

### Troubleshooting
* You've got an X server hanging around for some reason: assuming you don't actually need it, run the script with `--kill`, which'll murder any existing X servers and let the script set up its own.
* You've got an X server hanging around for some reason: assuming you don't actually need it, run the script with `--kill`, which'll murder any existing X servers and let the script set up its own. Sometimes the OS [might automatically recreate its X servers](https://unix.stackexchange.com/questions/25668/how-to-close-x-server-to-avoid-errors-while-updating-nvidia-driver), and that's [tricky enough to handle that it's up to you to sort out](https://unix.stackexchange.com/questions/25668/how-to-close-x-server-to-avoid-errors-while-updating-nvidia-driver).
* You've got a display attached: it won't work, but see [this issue](https://github.com/andyljones/coolgpus/issues/1) for progress.
* `coolgpus: command not found`: the pip script folder probably isn't on your PATH. On Ubuntu with the apt-get-installed pip, look in `~/.local/bin`.
* General troubleshooting:
Expand Down

0 comments on commit d5d081f

Please sign in to comment.