Why doesn't this python program terminate?

247 views Asked by At

I am new to Python and Fuse. I am working my way through somebody else's Fuse code which I have running on my system.

Here is the main method that starts the program:

if __name__ == '__main__':
    os.system('clear')
    print "\n[*] Filesystem has been started.\n==============================================="
    main(sys.argv[1], sys.argv[2])

Which calls this

def main(a, b):
    print "\n[*] Calling main method"
    FUSE(FuseHandler(a), b, foreground=True)

Which (I now know) calls the init method from Fuse... What is happening when this code calls FUSE like this?

class FuseHandler(Operations):
    '''
    Class must implement reading a file, writing a file, and listing a directory.
    POSIX calls will be redirected as such.
    '''
    def __init__(self, root):
        self.root = realpath(root)      
        # Set up a working directory in case this is the first run
        self.printStatus()
        print '[-] End of Fuse init method: system initialized'

When I run the program, it runs all the way to the end of the init method and then prints

"End of Fuse init method: system initialized."

But then the cursor blinks like Python is expecting input. The program does not terminate. What is it doing? Where does the code "go" after the call to Fuse init? Is that what a running Fuse console looks like?

enter image description here

1

There are 1 answers

4
Matteo Italia On

With the FUSE(...) call you are giving control to the FusePy library, which has to keep your program running (there's probably an event dispatch loop underneath); otherwise, how could your program keep responding to Fuse file operations requests (whose implementation is in your handler class) if it terminated immediately?