-2

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

Community
  • 1
  • 1
bernie2436
  • 22,841
  • 49
  • 151
  • 244

1 Answers1

2

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?

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • Seriously? It _could_ detach from the controlling tty and continue running in the background as a daemon. Which is not very likely, particularly considering the `foreground=True` argument given to the FUSE call. But in principle there are definitely ways that the program could return control to the user and yet continue handling requests, so your question here seems kind of silly. :-) – Tim Pierce Nov 30 '13 at 13:42
  • @MatteoItalia I am still getting a feel for Fuse. I get that control has been passed to the FUSE library. How do I then query fuse? from outside the program? Or from a method in main? Once Fuse init completes , does the stack return to the main method? There's got to a be loop somewhere if the program is continuing. Where is that loop? Within fuse? – bernie2436 Nov 30 '13 at 13:47
  • @qwrrty: double check what I wrote: I never said that you cannot return control to the shell, I said that the process cannot terminate if you want to continue handling fuse requests. The question is "why doesn't this python program terminate", not "how can I make it a daemon". – Matteo Italia Nov 30 '13 at 14:37
  • @akh2103: the loop is within the FUSE library (if there's not a loop, there's probably something similar, I don't know FUSE's inner workings). It will listen on some UNIX socket waiting for requests, and dispatch them to the appropriate methods of your class, which has to handle these requests according to the file system you are implementing. – Matteo Italia Nov 30 '13 at 14:42