python-watchdog

Watchdog getting events thrice in Python 3

懵懂的女人 提交于 2019-12-20 21:40:01
问题 I'm creating a program in Python using Watchdog that watches a set of files and takes actions based on changes. I put the exact example from their site in a file: import sys import time import logging from watchdog.observers import Observer from watchdog.events import LoggingEventHandler if __name__ == "__main__": logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S') path = sys.argv[1] if len(sys.argv) > 1 else '.' event_handler =

How do I watch a file, not a directory for changes using Python?

痞子三分冷 提交于 2019-12-12 10:44:41
问题 The question: How do I watch a file for changes using Python? suggests using watchdog, but I found it was only able to watch a directory, not a file. watchdog-test.py is watchdog's sample script: $ python watchdog-test.py ab_test_res.sh & [1] 30628 fbt@fbt64:~/laike9m$ Traceback (most recent call last): File "watchdog-test.py", line 15, in <module> observer.start() File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/api.py", line 255, in start emitter.start() File "/usr/local/lib

Python watchdog, watch a directory and rename file on event.modification

耗尽温柔 提交于 2019-12-11 17:18:14
问题 attempting to dive into classes() and I thought I'd make a real-world program that would help one of my colleagues at work. I'm using the watchdog API to watch a folder, the behavior I'm after is that when a file is moved into this folder I want to rename it according to course_name column in the csv, simple so far right? now when I run the above pseudo logic I keep getting a FileNotFoundError however the code does work - but the API is still searching for the file that was removed/changed?

Handling OSError from Watchdog

蹲街弑〆低调 提交于 2019-12-11 02:05:54
问题 I have been using tkinter combined watchdog module to handle some uploading requests. Most of the time it works fine, but sometimes our network drive goes unstable and disconnects for certain amount of time. However i am unable to find the correct place to catch this error. from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler import tkinter as tk root = tk.Tk() path = [r"Network path 1",r"Network path 2"] class MyGui: def __init__(self,master): self

How to run an function when anything changes in a dir with Python Watchdog?

送分小仙女□ 提交于 2019-11-29 09:38:19
问题 I'm trying to use watchdog to run a sync script whenever anything changes in a dir (except for one specific file). I simply copied the code from the readme (pasted below), which does what it says; log which file has changed. import sys import time import logging from watchdog.observers import Observer from watchdog.events import LoggingEventHandler if __name__ == "__main__": logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S') path = sys

Calling one method from another within same class in Python

时光毁灭记忆、已成空白 提交于 2019-11-28 07:33:28
I am very new to python. I was trying to pass value from one method to another within the class. I searched about the issue but i could not get proper solution. Because in my code, "if" is calling class's method "on_any_event" that in return should call my another method "dropbox_fn", which make use of the value from "on_any_event". Will it work, if the "dropbox_fn" method is outside the class? I will illustrate with code. class MyHandler(FileSystemEventHandler): def on_any_event(self, event): srcpath=event.src_path print (srcpath, 'has been ',event.event_type) print (datetime.datetime.now())

Simplest way for PyQT Threading

北战南征 提交于 2019-11-26 13:50:34
I have a GUI in PyQt with a function addImage(image_path) . Easy to imagine, it is called when a new image should be added into a QListWidget. For the detection of new images in a folder, I use a threading.Thread with watchdog to detect file changes in the folder, and this thread then calls addImage directly. This yields the warning that QPixmap shouldn't be called outside the gui thread, for reasons of thread safety. What is the best and most simple way to make this threadsafe? QThread? Signal / Slot? QMetaObject.invokeMethod? I only need to pass a string from the thread to addImage . I

Simplest way for PyQT Threading

◇◆丶佛笑我妖孽 提交于 2019-11-26 03:44:28
问题 I have a GUI in PyQt with a function addImage(image_path) . Easy to imagine, it is called when a new image should be added into a QListWidget. For the detection of new images in a folder, I use a threading.Thread with watchdog to detect file changes in the folder, and this thread then calls addImage directly. This yields the warning that QPixmap shouldn\'t be called outside the gui thread, for reasons of thread safety. What is the best and most simple way to make this threadsafe? QThread?