-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll.py
43 lines (32 loc) · 963 Bytes
/
poll.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import argparse
import shlex
import subprocess as sp
import time
import kaggle
def run(task_name):
cmd = "kaggle kernels status punzalan/{}".format(task_name)
# TODO: Expose increment as parameter
increment = 60
acc = 0
while True:
response = sp.run(shlex.split(cmd), stdout=sp.PIPE, stderr=sp.PIPE)
print(response.stdout.decode("utf-8"))
is_running = any(
map(
lambda elem: elem in response.stdout.decode("utf-8"),
["running", "queued"],
)
)
if not is_running:
break
# TODO: Expose sleep increment as parameter
time.sleep(5)
acc += 5
if acc >= increment:
acc = 0
print("slept {} seconds".format(increment))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--task_name")
args = parser.parse_args()
run(args.task_name)