Finish and shutdown
Posted: Sat Aug 21, 2021 6:36 pm
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
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/
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)
For those who want to run this script on Windows: you'll need Python (obviously): https://www.activestate.com/products/python/downloads/