Finish and shutdown

This forum contains information about 3rd party applications which may be of use to those who run the FAH client and one place where you might be able to get help when using one of those apps.

Moderator: Site Moderators

Post Reply
PaulTV
Posts: 211
Joined: Mon Jan 25, 2021 4:53 pm
Location: Netherlands

Finish and shutdown

Post by PaulTV »

It may be a nice function for an upcoming version of the client: finish running WUs and shutdown the computer. But since it doesn't exist, I made a little Python script myself. This one runs on Windows, but it should be pretty trivial to make it run on Linux, or make it portable. I may do the latter myself, and change the code here, eventually :)

Code: Select all

import telnetlib
import sys
import re
import json
import time
import subprocess

tn = telnetlib.Telnet('127.0.0.1', 36330)
tn.read_until(b'> ')

tn.write(b'slot-info\n')
slotinfo = tn.read_until(b'> ').decode('ascii').strip()
slotinfo = slotinfo.replace('\n', '').replace(' False', ' 0').replace(' True', ' 1')
m = re.fullmatch('PyON \d+ slots.*?(\[.*\]).*--->', slotinfo)
slotinfo = json.loads(m.group(1)) if m else []
for slot in slotinfo:
    if slot['status'] != 'PAUSED':
        print(f'Finish slot {slot["id"]}')
        tn.write(f'finish {slot["id"]}\n'.encode('ascii'))
        tn.read_until(b'> ')

while True:
    tn.write(b'queue-info\n')
    queueinfo = tn.read_until(b'> ').decode('ascii').strip()
    queueinfo = queueinfo.replace('\n', '').replace(' False', ' 0').replace(' True', ' 1')
    m = re.fullmatch('PyON \d+ units.*?(\[.*\]).*--->', queueinfo)
    queueinfo = json.loads(m.group(1)) if m else []
    if not queueinfo:
        print('No more entries in queue, shutting down')
        subprocess.Popen(['shutdown', '/s', '/t', '0', '/c', 'FAH jobs finished']).communicate()
        sys.exit(0)
    print(f'Waiting for {len(queueinfo)} job(s) to finish')
    time.sleep(30)
Edit: it's now changed to finish all slots that aren't paused. A paused slot may stay paused after a reboot (depending on the reason why it's paused), so that's why the script does not mess with that.

For those who want to run this script on Windows: you'll need Python (obviously): https://www.activestate.com/products/python/downloads/
Image

Ryzen 9800X3D / RTX 4090 / Windows 11
Ryzen 5600X / RTX 3070 Ti / Ubuntu 22.04
Ryzen 5600 / RTX 3060 Ti / Windows 11
Post Reply