Created
March 26, 2020 07:43
-
-
Save purpl3F0x/6f6c410b1a3c40084488c9dcff510d95 to your computer and use it in GitHub Desktop.
This file contains 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
import sys | |
import telnetlib | |
from ast import literal_eval | |
from time import sleep | |
HOST = "localhost" | |
DELIMITER = "\n>" | |
num_of_slots = 0 | |
tn = telnetlib.Telnet(HOST, port=36330) | |
def read_till_prompt(): return tn.read_until( | |
DELIMITER.encode('ascii')).decode('ascii') | |
def write(msg): | |
return tn.write((msg + '\n').encode('ascii')) | |
read_till_prompt() | |
write("num-slots") | |
try: | |
num_of_slots = int(read_till_prompt().split('\n')[2]) | |
print("Got number of slots ({})".format(num_of_slots)) | |
except ...: | |
print("Couldn't get # of slots") | |
tn.close() | |
sys.exit(0) | |
while (1): | |
min_eta = 2 << 31 | |
for i in range(num_of_slots): | |
write("simulation-info {}".format(i)) | |
sim_info = literal_eval(read_till_prompt().split('\n')[2]) | |
if sim_info['project'] == 0: | |
print("Requesting new work for slot {}", i) | |
# write("request-ws") | |
write("pause " + str(i)) | |
print(read_till_prompt()) | |
sleep(0.1) | |
write("unpause " + str(i)) | |
print(read_till_prompt()) | |
else: | |
print("Slot {} is working", i) | |
min_eta = min(min_eta, sim_info['eta']) | |
min_eta = max(min_eta, 60) | |
print("Sleeping for {} sec...".format(min_eta)) | |
sleep(min_eta) | |
tn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment