watchfiles icon indicating copy to clipboard operation
watchfiles copied to clipboard

[Question] Why does this not work?

Open mkornacker opened this issue 1 year ago • 2 comments

(I'm running this on Ubuntu.) I was expecting the following code snippet to print a single file addition, but path_generator doesn't return anything. I might be missing something obvious...

import watchfiles
import threading
import uuid
stop_event = threading.Event()
path_generator = watchfiles.watch('./wftest', stop_event=stop_event)
path = f'./wftest/{uuid.uuid4().hex[:8]}.txt'
with open(path, 'w') as f:
    f.write('hello')
stop_event.set()
for change_set in path_generator:
    print(change_set)

mkornacker avatar Apr 03 '23 03:04 mkornacker

Don't know for sure.

You might need to wait a little time for the changes to propagate!?

samuelcolvin avatar Apr 03 '23 07:04 samuelcolvin

I suspect this is because stop_event.set() is getting in the way. If you comment that out, you'll see your Change.added.

kevin-bates avatar Apr 21 '23 23:04 kevin-bates