( Joejszaka | 2013. 01. 03., cs - 16:10 )


import subprocess
import time
import threading
import ConfigParser

def check(ready, directory):
    #print "ls begin"
    res = subprocess.check_output(["ls", directory])
    #print "ls returned"
    ready[directory] = 1

def forceUnmount(mydir):
    params = "-l " + mydir;
    res = subprocess.check_output(["umount", "-l", mydir])

class MountChecker(object):
    def __init__(self, dirs):
        self.mounted_dirs = dirs
        self.ready = { '/': 0}

    def isResponsive(self, directory):
        self.ready[directory] = 0;
        mythread = threading.Thread(target = check, args=[self.ready, directory])
        mythread.start()
        time.sleep(0.01)
        if self.ready[directory] == 0:
            time.sleep(1)
        if mythread.isAlive():
            try:
                mythread._Thread__stop()
            except:
                print(str(mythread.getName()) + ' could not be terminated')
        return self.ready[directory]


    def do(self):
        for i in self.mounted_dirs:
            if self.isResponsive(i):
                print i + " is responsive"
            else:
                print i + " is NOT responsive"
                forceUnmount(i)

    def printDebug(self):
        for i in self.mounted_dirs:
            if self.isResponsive(i):
                print i + " is responsive"
            else:
                print i + " is NOT responsive"



mc = MountChecker(["/media/eee", "/media/Windows7_OS"]);
mc.do()