I'm new to Python and I'm trying to implement a good "file creation" detection. If I do not put a time.sleep(x)
my files are elaborated in a wrong way since they are still being "created" in the folder. (buffer is not empty)
How can I circumvent this thing without waiting x
seconds every time a file is created?
This is my code:
Main:
while 1:
if len(parser()) > 0: # arguments are valid
if len(parser()) == 3:
log_path = parser()['log_path']
else:
log_path = os.getcwd()
paths = parser()
if paths:
handler = Event_Handler()
observer = Observer()
observer.schedule(handler, paths['src_fld'], True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
else:
exit(1)
Event_Handler class:
class Event_Handler(FileSystemEventHandler):
def on_created(self, event):
if not event.is_directory:
time.sleep(1)
As I said, without that time.sleep(1)
if I try to process a big file I'll fail since it's still not completely written.