Need resource for worked examples for simple things

Hi all
working my way through the high level concepts and hitting a stumbling block. My first inclination is to look at a simple worked example and figure out what I don’t understand. So an example is that I wanted to look into FileWatching so I could monitor a folder. So the documentation gives you the basics BUT doesn’t seem to cover how the filename is returned. Here is my REPL example where I updated a text file called tst.tst.

julia> using FileWatching
shell> pwd

julia> watch_folder( "/home/dave/tontine_2022/just_messing", 60)
".goutputstream-RR4KG1" => FileWatching.FileEvent(true, false, false)


so the returned values should have been:
filename : but I got .goutputstream-RR4KG1"
event ; changed , renamed , and timedout : FileEvent(true, false, false)

So to my julia ignorant eye this tells me that “.goutputstream-RR4KG1” was changed but not how to get the filename. So what am I missing?

Also I would like to have a link to a resource where this is covered in an example. I tried searching discourse but FileWatching.watch_folder didn’t return anything.

thank you

I suspect that it is working as expected and
.goutputstream-RR4KG1 is the name of the file which changed. It’s created by Gnome

I would put it in a loop

    while true
        println(watch_folder( "/home/dave/tontine_2022/just_messing", 60))

I did that on my /home and got two events for echo > hi

"hi" => FileWatching.FileEvent(true, false, false)
"hi" => FileWatching.FileEvent(false, true, false)

The docs say

This will continuing tracking changes for path in the background until unwatch_folder is called on the same path .

So every time you call it, it will pop the last entry from inotify or whatever the local platform event montior is.

Julia itself doesn’t actually do the monitoring.

On Linux it uses this

1 Like

Thank you for the excellent reply.

I had done the same as you but created a file in Nautilus by RMC to see what would happen, then added a few lines to it and renamed it to “the tes” saved it and got the 4 events below. I am not STILL not certain what they are.

When you say they are from gnome how can I exclude them from the processing as they don’t seem relevant.

Please remember my OP was how do I find more examples regarding FileWatching. If you can show me where to find that info for this then I “hope” there is more for other areas. I can’t find anything that does the simple stuff like this.

julia> using FileWatching

julia> while true
               println(watch_folder( "/home/dave/tontine_2022/just_messing", 60))
"Untitled Document" => FileWatching.FileEvent(true, false, false)
"Untitled Document" => FileWatching.FileEvent(true, false, false)
"the tes" => FileWatching.FileEvent(true, false, false)
".goutputstream-ZE9QG1" => FileWatching.FileEvent(true, false, false)
".goutputstream-ZE9QG1" => FileWatching.FileEvent(false, true, false)
".goutputstream-ZE9QG1" => FileWatching.FileEvent(false, true, false)
".goutputstream-ZE9QG1" => FileWatching.FileEvent(true, false, false)
"the tes" => FileWatching.FileEvent(true, false, false)

while true
    filename, event = watch_folder("/home/dave/tontine_2022/just_messing", 60)
    if !startswith(filename, ".goutputstream")
        println(filename, " => ", (event.changed ? "changed" :
                                   event.renamed ? "renamed" :
                                   event.timedout ? "timed out" :
                                   error("Unknown event"))

This will both skip the .goutputstream files, and print the file event as a readable string.

For more examples about using FileWatching, you could try this SourceGraph search of code that uses the package (though you’ll have to do a bit of digging yourself to see where exactly the functions are being used in the code).

Edit: changed github search to SourceGraph, results seem much better there

1 Like

thanks digital the SourceGraph is much better. I’m coming from the python world where the examples are plentiful and clarity is king :slight_smile:

Thanks for the code but doesn’t it seem odd to you that it has to be done this way?

I can’t be the first to come across this UNLESS I don’t have the correct julia mental model. Which others in this forum have suggested.

All I wanted to do was monitor a folder for rational events and when they happen take resultant action. Finding the file events docs was the easy part. Figuring out how to code it was also easy

while true
      (file, event) = watch_folder(dir, 1)
      if event.changed
         figure out what to do

but then all these strange filenames start appearing and have to be handled. So what started out simply, monitor a folder and when something changes tell me the name of the the thing and what happened becomes something more.

@lawless-m did a great job pointing out where they come from but it’s further down the rabbit hole than I like. To follow up on his observation that it was gnome related I found this that explains it nicely
where do goutputstream files come from which offers the solution to ignore them and try again a few seconds later which seems to be the case.

I agree with the general point that more worked examples would be good - Julia community is making good progress towards catching up with Python or other languages that have had decades of writing examples, blog posts, tutorials, etc., and there’s still work to be done.

But in this case, the rabbit hole has nothing to do with Julia; any library in any language that does file watching will report the same things, and will need the same kind of filtering. Julia is reporting back what changed in the filesystem - just as we ask it to, and just like any other language will - and it cannot by itself decide what is and isn’t an important event to report: that’s for us to decide depending on our use case.

hi @digital_carver
julia is 10 years old isn’t it? This functionality seems to be pretty basic and I would have thought others would have covered it. So in this case it’s a set of temporary files that get created momentarily then disappear, yes it can be coded out but shouldn’t watch_folder have a argument that considers that so we don’t have to. If julia knows we are using gnome then…

NOW I am not being critical, it’s just to a noob like me this isn’t tip top. I don’t code for a living and that’s why python is such a great choice.

this is NOT my code but makes my point. Easy to locate, helps to make me a better “coder”, gets the job done and I wonder how it would handle .goutputstream. Seems it handles vim temp files pretty well and it’s clear what is happening.

how to scan file events in python

That link is just someone’s blog, someone just like you. Someone who came across some library code, wrote a few bits with it until it worked and then wrote a blog post about it. Today could be the day you write a blog post about FileWatching in Julia.



OH that I was such a great coder :slight_smile: Right now I’m trying to just get to get off to a sensible start. Something I did NOT do with python. All my code was mindless hack jobs cobbled together to just get the job done. The only time I took a step back was with pandas. WOW that was FUN!!! I learnt a LOT and was STUNNED the small amount of code I had to write to get complex things done. I am hoping julia will be the same experience once I get into the swing of things. It’s not too bad it’s just stuff like this that trips me up. Thanks for all your great help.