How to get event on a big file write

67 views
Skip to first unread message

Rohit Gupta

unread,
Oct 1, 2020, 4:24:16 PM10/1/20
to watchdog-python
Hi people,
I'm watching for events on a directory, where some other writer process is writing big files,
so I get created event immediately, and gets modified event while the buffer is being filled for that file.
I'm wondering how do I know that the write to that file has finished, as i want to trigger a move after that.

-
Rohit

Anthony Crawford

unread,
May 25, 2021, 11:15:01 PM5/25/21
to watchdog-python
I am also interested in an event that triggers when a file is finished being created. 
My use case refers to uploading video files to a server watch folder. I need the "new file" event to trigger when the file has completed uploading (finished being created), not when the file has begun to be created.
The watchdog.observers.inotify_buffer has an InotifyEvent mask called "IN_CLOSE_WRITE" which is sent when the file is finished uploading, however I do not know how to reference this.

Chris Nyland

unread,
Jun 4, 2021, 9:32:43 AM6/4/21
to watchdog-python
If it is on Windows the behavior is a bit funky you need to watch the on_modified event. This event is sent multiple times while the file is being written. You will have to setup a try except where you try and do something with the file if it isn't finished copying they you will likely get some kind of OSError. When the file finishes you should get one last on_modified event at this point the lock on the file from the Windows OS should be released and your processing should work. If you on Linux I think the inotify mechanism that watch dog uses has more fine grain events so there should be an even for file copy or move. 

Chris

Reply all
Reply to author
Forward
0 new messages