#!/usr/bin/env python3
import os
import time
import shutil

def workdirs():
    numfolders = []
    for item in os.listdir('.'):
        try:
            numfolders.append(int(item))
        except ValueError:
            pass #Not int no add.
    return numfolders

print("Will now check directory and if it hangs, kills process and removes.")
while True:
    last = workdirs()
    time.sleep(60*15) #15min
    new = workdirs()
    if( last == new ):
        print('stuck, killing')
        print(last)
        os.system('killall java');
        os.system('mv ./'+str(new[0])+' ../later/' )
